我有一个像这样的SQL代码,
SELECT *,
(Select Count(PostID) FROM Likes Where Likes.PostID = Posts.PostID) AS Likes,
(Select Count(PostID) FROM Comments WHERE Comments.PostID = Posts.PostID) AS Comments
FROM Posts
但是我需要用EntityFramework 5编写这段代码。我怎么能写这段代码? 感谢。
答案 0 :(得分:0)
from post in Posts
select new
{
Post = post,
Likes = (from like in Likes where like.PostID == post.PostID select like).Count(),
Comments = (from comment in Comments where comment.PostID = post.PostID select post).Count()
}