I'm using LINQKit to expand LINQ To Entities capabilities:
public Boolean IsMatched(Int32 age)
{
return age > 18;
}
public IQueryable<Users> GetAllMatchedUsers(Func<Int32, Boolean> isMatched)
{
return qry = _Context.Users.AsExpandable().Where(x => x.IsActive && isMatched(x.Age));
}
This code is used for Entity Framework ORM objects (_Context is DbContext, Users - is DBSet)
This code throws following exception
Unable to cast object of type 'System.Linq.Expressions.FieldExpression' to type 'System.Linq.Expressions.LambdaExpression'
Getting rid of Func and hardcoding IsMatched into GetAllMatchedUsers solves this problem. But I need to use Func to pass different selection criteria from Business Logic Layer to my Data Access Layer
P. S. IsMatched is highly simplified realisation for example of course
Help me please.