自我加入实体框架

Wah*_*eed 3 c# entity entity-framework

我想在实体框架工作中有以下类型的查询

SELECT  c2.* 
FROM    Category c1 INNER JOIN Category c2
ON      c1.CategoryID = c2.ParentCategoryID
WHERE   c1.ParentCategoryID is NULL
Run Code Online (Sandbox Code Playgroud)

如何在Entity框架中完成上述工作......

Jon*_*eet 9

好吧,我对EF知之甚少,但看起来像是:

var query = from c1 in db.Category
            where c1.ParentCategoryId == null
            join c2 in db.Category on c1.CategoryId equals c2.ParentCategoryId
            select c2;
Run Code Online (Sandbox Code Playgroud)

  • @Waheed:我不知道你的意思 - 你应该能够在EF中使用那个确切的查询. (3认同)