I have a feeling I already know the answer to this question.
I have an expression that common but complex, and I would like to re-use the code in multiple locations. I would like to use a function that returns a Func with some code:
public static Func<MyClass, bool> GetCheck()
{
return (x) => x.Value > 10;
}
Seems easy. The problem that I'm having is when I apply it to a LINQ expression that's used in LINQ To Entities. I get an error that says Invoke is not supported. And I understand why. What I don't know is if there's a way that I can get around this. I would like to say...
var check = GetCheck();
IQueryable<MyClass> results = MyClasses.Where(y => check(y));
... and have the expression tree inspector realize that everything that happens in the Func is perfectly legal both in LINQ To Entities and on the DB. It seems like it should be inline'd.
Is there anything I can do to make this happen? Any form of declaration for the delegate that will allow this?