您可以帮忙将此查询转换为linq ??
SELECT DISTINCT Users.IDUsr, Users.Name
FROM [UserGroups.UnitType] INNER JOIN
[UserGroups.Units] ON
[UserGroups.UnitsTypes].IDUGOUT = [UserGroups.Units].IDUGOUT
RIGHT OUTER JOIN
Users INNER JOIN [Users.Groups] ON Users.IDUsr = [Users.Groups].IDUsr
INNER JOIN UserGroups ON [Users.Groups].IDUsrGrp = UserGroups.IDUsrGrp
ON [UserGroups.OrganizationUnits].IDUsrGrp = UserGroups.IDUsrGrp
WHERE (Users.Removed = 0) AND ([UserGroups.UnitsTypes].Type <> 100) OR
([UserGroups.UnitsTypes].Type IS NULL)
答案 0 :(得分:1)
答案 1 :(得分:1)
我认为你的一些代码被修剪了。它依赖于1个完全不存在的表。
这是我能看到的最好的事情:
var query =
(
from u in Users
from g in u.UsersGroups
from un in g.Units.DefaultIfEmpty()
let t = un.UnitsType
where u.Removed == 0 && (t.Type <> 100 || t.Type == null)
select new { ID = u.IDUsr, Name = u.Name }
).Distinct()