MongoDb NoRM Linq 问题

发布于 2024-09-12 18:35:39 字数 470 浏览 2 评论 0原文

我正在尝试使用 C# 中的 NoRM 来使用 MongoDB,但不明白为什么我的 LINQ 查询不起作用。事情就这么简单:

如何返回具有所有字段/属性的所有文档 populated:

    return Collection.FindAll().Documents.ToList(); 

但是这个只返回正确数量的文档 ID 字段已填充?对象的其余部分是空的/空的吗?

    return Collection.Linq().ToList(); 

以下是集合的定义方式:

    public IMongoCollection<T> Collection 
    { 
        get { return _database.GetCollection<T>(); } 
    } 

I'm trying MongoDB with NoRM in C# and can't figure out why my LINQ queries don't work. Something as simple as this:

How can this return all documents with all the fields/properties
populated:

    return Collection.FindAll().Documents.ToList(); 

but this one only returns the correct number of documents with only
the ID field populated? The rest of the object are empty/nulls?

    return Collection.Linq().ToList(); 

Here is how collection is defined:

    public IMongoCollection<T> Collection 
    { 
        get { return _database.GetCollection<T>(); } 
    } 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事灯 2024-09-19 18:35:39

Linq 方法从何而来?如果您想将集合中的所有项目返回到列表中,则以下两个选项之一应该有效...

return Collection.AsQueryable().ToList();

return Collection.Find().ToList();

Where does the Linq method come from? If you want to return all items in the collection into a List, one of the two following options should work...

return Collection.AsQueryable().ToList();

return Collection.Find().ToList();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文