I am using LinqKit and I want to write a predicate in which the code has to call a plain boolean method, like this :
var predicate = PredicateBuilder.False<MyEntity>();
var predicate = predicate.And(myEntity => this.EntityMatches(myEntity));
this.ObjectSet.AsExpandable().Where(predicate).ToList();
Here is (part of) the EntityMatches method :
private bool EntityMatches(MyEntity myEntity)
{
bool isMatch;
// I make a call to another library boolean method here.
isMatch = otherLib.IsEntityMatch(myEntity);
// I perform some other checks right after.
isMatch &= // some other conditions ...
return isMatch;
}
I get this exception when running deferred execution :
LINQ to Entities does not recognize the method 'Boolean EntityMatches(MyEntity)' method, and this method cannot be translated into a store expression.
How can I rewrite the EntityMatches method so it is understandable by the store provider ?