我有以下课程:
public class Company
{
[BsonId]
public string dealerId = null;
public List<Dealer> dealers = new List<Dealer>();
}
public class Dealer
{
public string dId = null;
public int dIndex = -1;
public List<AutoStore> stores = new List<AutoStore>();
}
public class AutoStore
{
public string type = null;
public Dictionary<string, object> data = new Dictionary<string, object>();
}
我可以将Company类对象存储在 Mongo 中Insert()。问题是当我搜索文档并尝试对List<>项目使用 LINQ 时。我经常遇到异常。
var query = collection.AsQueryable<Company>()
.Where(cpy =>
cpy.dealers.Where(dlr =>
dlr.stores.Count == 1).Count() > 0) ;
运行此代码,我得到:
System.NotSupportedException:无法确定表达式的序列化信息:Enumerable.Count
我今天刚开始使用Mongo,但我认为LINQ支持更成熟。谁能告诉我是否可以像使用C#and那样进行嵌套数组查询LINQ?
只要我删除Where()任何一个List<>,就不会抛出该异常