3 回答
TA贡献1821条经验 获得超4个赞
该语句不需要子查询,最好写成
select u.*
from Users u, CompanyRolesToUsers c
where u.Id = c.UserId --join just specified here, perfectly fine
and u.lastname like '%fra%'
and c.CompanyRoleId in (2,3,4)
要么
select u.*
from Users u inner join CompanyRolesToUsers c
on u.Id = c.UserId --explicit "join" statement, no diff from above, just preference
where u.lastname like '%fra%'
and c.CompanyRoleId in (2,3,4)
话虽这么说,在LINQ中
from u in Users
from c in CompanyRolesToUsers
where u.Id == c.UserId &&
u.LastName.Contains("fra") &&
selectedRoles.Contains(c.CompanyRoleId)
select u
要么
from u in Users
join c in CompanyRolesToUsers
on u.Id equals c.UserId
where u.LastName.Contains("fra") &&
selectedRoles.Contains(c.CompanyRoleId)
select u
同样,这两种方式都是代表这一点的可敬方式。我本人在这两种情况下都希望使用显式的“ join”语法,但是它有...
TA贡献1829条经验 获得超4个赞
这就是我在LINQ中进行子查询的方式,我认为这应该得到您想要的。您可以使用另一个子查询替换显式的CompanyRoleId == 2 ...来替换您想要的不同角色,或者也可以将其加入。
from u in Users
join c in (
from crt in CompanyRolesToUsers
where CompanyRoleId == 2
|| CompanyRoleId == 3
|| CompanyRoleId == 4) on u.UserId equals c.UserId
where u.lastname.Contains("fra")
select u;
- 3 回答
- 0 关注
- 1112 浏览
添加回答
举报