2013-03-10 63 views
1

需要帮助的LINQ表达, 我有2个表Articlecomments外键是Article_id。现在,我需要同时使用使用LINQ的表中的数据,以SQL LIKE article_id,Article_title,Total_Comments(评论计数根据目前的第条),如何使用聚合函数工作在LINQ与加入

故事结构:

table 1(Article) : Article_ID,Article_Title.. etc 
table 2(comments): Comment_auto_id,Comment_text,Comment_by(User_ID),Article_ID 
+0

不'文章'有导航属性'评论'? – 2013-03-10 10:20:07

回答

1

类似的东西?

from article in Articles 
join comment in Comments on article.Article_ID equals comment.ArticleID into articleComments 
select new { 
    Article = article,//or more detailed if you want only part of Articles entity 
    Total_Comments = articleComments.Count() 
} 
+0

thanx亲爱的将会有“等于”而不是“=”。这就是我想要的。我在分组时非常抱歉:非常感谢。祝你有个愉快的日子 – 2013-03-10 07:12:43

+0

@Anupam哦,你是对的,编辑过。 – 2013-03-10 07:47:52