Can someone help me with this please? I would like a simple 'where in'. Here's the SQL that does what I want.
select ur.RoleID
from UserRoles ur
where ur.RoleID in (5, 15)
And here's my attempt. The method .IN() doesn't exist obviously, just put my aggrevated thoughts lol.
int roleid;
foreach (data r in dataList) {
using (DataContext communityContext = new DataContext()) {
roleid = communityContext.UserRoles
.Where(x => x.UserID == r.ClientId && x.RoleID.IN(5, 15))
.Select(x => x.RoleID)
.First();
}
}
As you mention In
doesn't exist, se .Contains()
instead if you have a list, in your case you could also use x.RoleId == 5 || x.RoleId == 15
e.g.
var allowedRoles = new int[] { 5, 15 };
then in your where
clause do:
allowedRoles.Contains(x.RoleID)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With