I want to use Where method in Linq 2 entities that will be equal to this
userRepository.Users.Where(u=>u.RoleID == 1 || u=>u.RoldID == 2).Select(o => new SelectListItem { Text = o.Role.RoleName, Value = o.RoleID.ToString() }).ToList();
The problem of course is in Where(u=>u.RoleID == 1 || u=>u.RoldID == 2)
The problem is that I don’t know how to use WHERE method with OR inside the WHERE clause.
any ideas (the code above will not compile of-course b/c of the lambda expression.
userRepository.Users returns an list of Users entities.
I guess that and can be done using concatenation of .Where().Where() but I need an OR.
Just remove the extra u=>
In your code, you try to “or” the lambdas, “lambda1 OR lambda2”, this is not possible as you’ve noticed.
You can however “or” the expression inside the lambda:
lambda(expression1 OR expression2)
Read the code as:
(User user)
{
return user.RoleId == 1 || user.RoleId == 2;
}
If that makes things clearer..
Also, I guess you have a typo on the last part “u.RoldId == 2”, instead of RoleId..