Help convert to linq

Hi, can anyone help convert this query to 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)
+3
source share
2 answers

I think part of your code is cut off. It relies on 1 table, which is not at all.

This is the best I can do with what I see:

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()
+1
source

I don't know linq right now, but using tools like linqer and linqpad should help in getting the correct syntax.

+1
source

Source: https://habr.com/ru/post/1734444/


All Articles