2012-10-13 74 views
1

我還在學習的實體表現的繩索,我有這樣的SQL查詢,我想實現到實體表達有麻煩,查詢是:與特定LINQ到實體表達

SELECT classname,abbreviation, cid 
      FROM [db].[dbo].[classes] AS c 
      WHERE c.cid IN (
       SELECT DISTINCT(CID) 
       FROM [db].[dbo].[CDS] 
       WHERE 
         sid = '1' 
         AND 
         did = '24' 
        ) 
      ORDER BY abbreviation, classname 

我該如何去執行實體表達式的查詢?

+0

這是什麼問題? –

回答

0

的表達應該是:

context.Classes.Where(C => 
       (context.CDS.Where(CD => CD.sid == "1" && CD.did == "24") 
       .Distinct(CD => CD.CID)).Contains(C.CID)) 
       .Select(C => new { 
            className = C.className, 
            abbreviation = C.abbreviation, 
            cid = C.cid 
           }); 

希望這將幫助!