tags:

views:

79

answers:

2

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)
+1  A: 

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.

Ben
already tried :S without success
Luis
+1  A: 

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()
David B