Question

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);  

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.

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

Était-ce utile?

La solution

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

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

var test = this.MongoConnectionHandler.MongoCollection.AsQueryable().AsExpandable<Message>().Where(predicate).ToList();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top