1

我仍在学习 Entity 表达式的技巧,我有这个 SQL 查询,我想在 Entity 表达式中实现,查询是:

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 

我将如何将该查询实现到实体表达式中?

4

1 回答 1

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

希望这会有所帮助!

于 2012-10-13T18:25:40.173 回答