有谁能够成功地从albahari.com对MongoDB使用PredicateBuilder? [英] Has anyone been able to use successfully PredicateBuilder from albahari.com against MongoDB?

查看:86
本文介绍了有谁能够成功地从albahari.com对MongoDB使用PredicateBuilder?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用albahari.com上流行的PredicateBuilder使用以下代码:

I have the following code using the popular PredicateBuilder from albahari.com:

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()的包含操作即可返回匹配的记录.

The problem is that it doesn't return anything even though there are records in that column which contain the letter 'a'. Removing the predicate builder and just doing contains directly off of AsQueryable() returns the matching records.

有人能够在Mongo上成功使用PredicateBuilder库吗?

Has anyone been able to use the PredicateBuilder library successfully with Mongo?

推荐答案

我在这里的类似问题中找到了解决方案: https://stackoverflow.com/a/21462366/1316683

I found the solution in a similar question here: https://stackoverflow.com/a/21462366/1316683

基本上添加LinqKit库并将AsExpandable添加到此行:

Basically add the LinqKit library and add AsExpandable to this line:

var test = this.MongoConnectionHandler.MongoCollection.AsQueryable().AsExpandable<Message>().Where(predicate).ToList();

这篇关于有谁能够成功地从albahari.com对MongoDB使用PredicateBuilder?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆