Reputation: 2192
I am working on entity framework project, i have to apply Or condition in dbContext.Where I have tried this but its giving me error "Operator || cannot be applied to operand of types lambda expressions"
return dataContext.Friends
.Where((r => r.ToUserId == touserid && r.FromUserId == fromuserid)
|| (r => r.ToUserId == fromuserid&& r.FromUserId == touserid ))
.ToList();
I also tried using && instead of || but its giving me same error for &&,how can i apply Or condition for this senario? I have tried without brackets as well
Upvotes: 0
Views: 3887
Reputation: 95
@Syed
|| (r => r.ToUserId == fromuserid&& r.FromUserId == touserid )).ToList();
Should be
|| (r => r.ToUserId == fromuserid && r.FromUserId == touserid )).ToList();
note the space between the "fromuserid&&".
Upvotes: -2
Reputation: 12513
Put it into one lambda that includes the ||
instead of ||
ing two separate lambas:
return dataContext.Friends.Where(r => (r.ToUserId == touserid && r.FromUserId == fromuserid) || (r.ToUserId == fromuserid&& r.FromUserId == touserid)).ToList();
Upvotes: 4
Reputation: 174299
You need to do it like this:
return dataContext.Friends.Where(r => (r.ToUserId == touserid && r.FromUserId == fromuserid) || (r.ToUserId == fromuserid && r.FromUserId == touserid))
.ToList();
The only difference is that I deleted the second r =>
and fixed the parenthesis.
Upvotes: 5