简体   繁体   English

mongodb c#驱动程序SelectMany linq运算符

[英]mongodb c# driver SelectMany linq operator

Hi I upgrade my mongodb driver to 2.2.3.3 version and I want to use SelectMany operator to query nested document.But when I try to execute my query I get "The SelectMany query operator is not supported error". 嗨,我将mongodb驱动程序升级到2.2.3.3版本,我想使用SelectMany运算符查询嵌套文档。但是当我尝试执行查询时,出现“不支持SelectMany查询运算符错误”。 Here is my code: 这是我的代码:

MongoDatabase database;
var client = new MongoClient("mongodb://myconnection");
var server = client.GetServer();
database = server.GetDatabase("MyDB");
MongoCollection<DGTable> collection;
collection = database
    .GetCollection<DGTable>(typeof(DGTable).Name);

var result = collection.AsQueryable()
    .SelectMany(p => p.TableColumns);
var abc = result.ToList();

You can postpone the call to .SelectMany(...) until after you have the data. 您可以.SelectMany(...)的调用推迟到拥有数据之后。 The method call doesn't increase the amount of data or does some db-specific-performance operation, so there is no explicit reason to call it within the query. 该方法调用不会增加数据量或执行某些特定于数据库的性能操作,因此没有明确的理由在查询中调用它。

var result = collection.AsQueryable()
    .Select(p => p.TableColumns)
    .ToList();
var abc = result
    .SelectMany(p => p)
    .ToList();

I find solution,I have some obsolute methods and I upgrade my code to new methods then it works 我找到了解决方案,我有一些绝对的方法,我将代码升级到新方法,然后就可以了

      var client = new MongoClient("mongodb://myconnection");

        var db = client.GetDatabase("mydb");
        var col = db.GetCollection<DGTable>("DGTable");

        var sadsdadas = col.AsQueryable().SelectMany(p => p.TableColumns).ToList();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM