简体   繁体   中英

Subqueries in linq

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

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 };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM