I have the following query which works fine in SSMS. Im using LinqPad (C#) but really puzzling to succeed with the left outer join in LinqToSql:
SELECT DISTINCT
A.LocID,
V1.PrfValue AS pID,
V2.PrfValue AS sID,
D.DivisionManager,
A.IsApproved,
A.DateCreated
FROM
dbo.Locations AS A
INNER JOIN
dbo.Divisions AS D
ON A.DivisionID = D.DivisionID
LEFT OUTER JOIN
dbo.ValuesInLocations AS V1
ON A.LocID = V1.LocID
AND
V1.PrfID IN (SELECT
PrfID
FROM
dbo.PrfTag
WHERE
(LevelTypeID = 1))
LEFT OUTER JOIN
dbo.ValuesInLocations AS V2
ON A.LocID = V2.LocID
AND
V2.PrfID IN (SELECT
PrfID
FROM
dbo.PrfTag
WHERE
(LevelTypeID = 2))
As you can see, this isn t the most elegant query to begin work, and I agree that the subquery in both left joins could be improved. However, could you please help me with this translation??