2013-03-10 61 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