Linq to SQL DynamicInvoke(System.Object[])' has no supported translation to SQL.
- by ewwwyn
I have a class, Users.
Users has a UserId property.
I have a method that looks something like this:
static IQueryable<User> FilterById(this IQueryable<User> p, Func<int, bool> sel)
{
return p.Where(m => sel(m));
}
Inevitably, when I call the function:
var users = Users.FilterById(m => m > 10);
I get the following exception:
Method 'System.Object DynamicInvoke(System.Object[])' has no
supported translation to SQL.
Is there any solution to this problem? How far down the rabbit hole of Expression.KillMeAndMyFamily() might I have to go?
To clarify why I'm doing this: I'm using T4 templates to autogenerate a simple repository and a system of pipes. Within the pipes, instead of writing:
new UserPipe().Where(m => m.UserId > 10 && m.UserName.Contains("oo") && m.LastName == "Wee");
I'd like to generate something like:
new UserPipe()
.UserId(m => m > 10)
.UserName(m => m.Contains("oo"))
.LastName("Wee");