EntityFramework : FindBy (column name) select arbitrary column by expression tree

c# entity-framework entity-framework-6 linq

Popular Answer

Changing the signature

IQueryable<User> FindBy(Expression<Func<User, bool>> predicate)
{
    return context.Users.Where(predicate);
}

You may dial

return FindBy(u => u.Username == username);

There isn't much code modification, therefore you don't need to make up expressions.

There must be an expression entered, not aFunc ) due to the fact that expressions can be converted into SQL. AFunc is simply a.Net delegate, and there is no equivalent in SQL.

1
4/6/2014 9:28:30 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow