Can some one help me to conver it into LINQ i m using Entity Framework
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.
精彩评论