开发者

Can some one help me to conver it into LINQ i m using Entity Framework

开发者 https://www.devze.com 2022-12-16 07:50 出处:网络
selectForumCategories.ID ,ForumCategories.Title , ForumCategories.DateCreated, CO = ( select COUNT(*) from ForumSubCategories where Forum开发者_开发知识库SubCategories.CategoryID_FK = ForumCategories.

select ForumCategories.ID , ForumCategories.Title , ForumCategories.DateCreated, CO = ( select COUNT(*) from ForumSubCategories where Forum开发者_开发知识库SubCategories.CategoryID_FK = ForumCategories.ID) from ForumCategories


var q = from fc in Context.ForumCategories
        select new 
        {
            Id = fc.ID,
            Title = fc.Title,
            DateCreated = fc.DateCreated
            CO = fc.ForumSubCategories.Count()
        };
return q;

The "join" (subquery) is implicit; it's defined in the relationship between ForumCategories and ForumSubCategories in your model. Using this syntax, the call to Count() will be done on the DB server.

0

精彩评论

暂无评论...
验证码 换一张
取 消