我使用 albahari.com 中流行的 PredicateBuilder 编写了以下代码:
var predicate = PredicateBuilder.False<Message>();
predicate.Or(p => p.Subject.Contains("a"));
var test = this.MongoConnectionHandler.MongoCollection.AsQueryable().Where(predicate).ToList();
return this.MongoConnectionHandler.MongoCollection.AsQueryable().Count(predicate);
问题是,即使该列中有包含字母“a”的记录,它也不会返回任何内容。删除谓词构建器并直接执行包含 AsQueryable() 返回匹配的记录。
有人能够成功地将 PredicateBuilder 库与 Mongo 一起使用吗?
我在这里找到了类似问题的解决方案:https://stackoverflow.com/a/21462366/1316683 https://stackoverflow.com/a/21462366/1316683
基本上添加 LinqKit 库并将 AsExpandable 添加到此行:
var test = this.MongoConnectionHandler.MongoCollection.AsQueryable().AsExpandable<Message>().Where(predicate).ToList();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)