如何将 MOngoDB.BsonDocumnet 转换为 C# 中的集合列表?
我有 MongoDB.BsonDocument,我想将该 BsonDocument 转换为集合列表,我该如何执行此操作,我将示例代码粘贴到下面...
try
{
var server = MongoServer.Create("localhost:27017");
var db = server.GetDatabase(DATABASE);
var riskdata = db.GetCollection("TABLESAMPLE");
var query = Query.EQ("Name", null);
var results = riskdata.Find(query);
gridsample.ItemsSource = results;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
但上面的代码对我不起作用...“_id”仅绑定到网格,剩余的字段不会来。
I have MongoDB.BsonDocument, i want to convert that BsonDocument to List of collection, how can i do this one, i paste my sample code below...
try
{
var server = MongoServer.Create("localhost:27017");
var db = server.GetDatabase(DATABASE);
var riskdata = db.GetCollection("TABLESAMPLE");
var query = Query.EQ("Name", null);
var results = riskdata.Find(query);
gridsample.ItemsSource = results;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
but above code not working for me...."_id" only binding to grid, remaining fields are not coming.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的网格可能不理解
BsonDocument
。您需要查看将这些 BSON 文档序列化为类 。
它将看起来像这样:
然后您更改查找以返回这些内容
现在您将拥有一个具有网格可以读取的属性的类。
It is likely that your grid does not understand
BsonDocument
.You need to take a look at serializing those BSON documents into classes.
It will look something like this:
Then you change your find to return these things
Now you will have a class with properties that your grid can read.
您可以通过将 BsonBocument 转换为数据表而不声明类来将 BsonDocument 与任何结构绑定
you can bind BsonDocument with any structure by convert BsonBocument to Data table without declare class