Hi can someone help to 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)
I think some of your code got clipped. It relies on 1 table that isn't there 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()
I don't know the linq right off hand, but using tools such as linqer and linqpad should be able to help with getting the correct syntax.
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