views:

113

answers:

1

Hello,

I've been trying for a couple of days to write to "translate" this query in LINQ with no success so far. Could you guys please help me? I would also appreciate some explanation to learn actually something out of it.

Here is the T-SQL query:

SELECT R.ResourceID, R.DefaultValue
FROM Resources as R
JOIN
    (SELECT [t0].[NameResourceID] AS [ResourceID]
    FROM [dbo].[Sectors] AS [t0]
    LEFT OUTER JOIN [dbo].[LocalizedResources] AS [t1] ON [t0].[NameResourceID] = [t1].[ResourceID] and [t1].[LanguageID] = 2
    WHERE t1.Value IS NULL)  AS subQ 

ON R.ResourceID = subQ.ResourceID

Thank's

A: 

Try something like that :

from r in db.Resources
join subQ in (from t0 in db.Sectors
              join t1 in db.LocalizedResources on t0.NameResourceID equals t1.ResourceID
              where t1.LanguageId
              && t1.Value == null
              select new { ResourceID = t0.NameResourceID }) on r.ResourceID equals subQ.ResourceID
select new { r.ResourceId, r.DefaultValue };
Thomas Levesque
Unfortunately this doesn't work. It gets translated in TSQL into: SELECT [t0].[ResourceID], [t0].[DefaultValue]FROM [dbo].[Resources] AS [t0]INNER JOIN ([dbo].[Sectors] AS [t1] INNER JOIN [dbo].[LocalizedResources] AS [t2] ON [t1].[NameResourceID] = [t2].[ResourceID]) ON [t0].[ResourceID] = [t1].[NameResourceID]WHERE 0 = 1I've tried to modify it but I couldn't get any better.