How do I get values of Linq Expression
Posted
by
Yucel
on Stack Overflow
See other posts from Stack Overflow
or by Yucel
Published on 2010-12-23T14:31:22Z
Indexed on
2010/12/23
14:53 UTC
Read the original article
Hit count: 236
Hi, I have a method that takes Expression type parameter, in my method i want to get values of this expression but cant find out hot to do that.
private User GetUser(Expression<Func<User, bool>> query)
{
User user = Context.User.Where(query).FirstOrDefault();
return user;
}
I am calling this method with different parameters like
GetUser(u => u.Username == username);
GetUser(u=> u.Email == email);
I want to change GetUser method to work with stored procedures but i need to find what is inside query parameter
I want to check if query is u.Username == username I will call GetUserByUsername SP if query is u.Email == email I will call GetuserByEmail SP
© Stack Overflow or respective owner