每当我在一个方法上使用断点来插入一个文档时,我得到一个"找不到MongoClient.cs"问题。我仍然可以连接到服务器并检索文档,如果它可以帮助,则为2.6.5,而C#驱动程序是版本1.10。我甚至从github存储库下载了MongoClient.cs文件以在Visual Studio中使用,但是我收到一条错误消息,指出源文件与构建的模块不同。
using MongoDB;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using MongoDB.Driver.Builders;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
MongoClient mongoClient { get; set; }
MongoServer server { get; set; }
MongoDatabase database { get; set; }
MongoCollection<facultyData> collection { get; set; }
BindingList<facultyData> resultBinding { get; set; }
public MainWindow()
{
InitializeComponent();
}
public void addData_Click(object sender, RoutedEventArgs e)
{
try
{
MongoClient mongoClient= new MongoClient();
var server = mongoClient.GetServer();
var database = server.GetDatabase("facultyDataAndSchedule");
var collection = database.GetCollection<facultyData>("faculty");
var results = collection.FindAll();
List<facultyData> resultList = results.ToList<facultyData>();
BindingList<facultyData> resultBinding = new BindingList<facultyData>(resultList);
try
{
var entity = new facultyData
{
facultyID = facultyID_Textbox.Text.ToString(),
term = termComboBox.SelectedItem.ToString(),
age = int.Parse(age_TextBox.Text),
acadYear = "2014-2015",
firstName = firstName_TextBox.Text.ToString(),
lastName = lastName_TextBox.Text.ToString(),
middleName = middleName_TextBox.Text.ToString(),
dateOfBirth = dateOfBirth_TextBox.Text.ToString(),
program = "progra",
rank = "gegs",
services = "gegsg",
status = "geh",
yearsOfTeachingO = 1,
yearsOfTeachingS = 1
};
collection.Insert(entity);
}
catch (FormatException ex)
{
Console.WriteLine(ex);
}
resultBinding.ResetBindings();
if (resultBinding.Count() > 0)
{
Binding bind = new Binding(); //create a new binding to be used on the wpf
facultyDataGrid.DataContext = resultBinding; //sets the data binding for the control
facultyDataGrid.SetBinding(DataGrid.ItemsSourceProperty, bind); //syncs the data
}
}
catch (MongoConnectionException ex)
{
Console.WriteLine(ex);
}
}
答案 0 :(得分:0)
无法找到该文件。您正在使用的Mongo客户端是已编译的程序集,而不是Visual Studio要用于单步执行和断点的代码和调试文件。您收到代码文件与构建的模块不同的通知也是正常的。在代码文件中,您可能会找到不在构建模块中的调试等的汇编条件。
长话短说,你所经历的是正常的,你通常不需要逐步完成分布式组装。