我有一個LINQ聲明我正在試圖弄清楚,所以也許會出現這種情況。我的目標是查詢一個表並加入另一個表以獲得計數。LINQ從加入組計數
地方
ID,顯示器
ProfilePlaces
ID,PlaceID,交流,聽到
基本上Places
具有在一個ProfilePlaces
一對多關係。我想獲得ProfilePlaces
的編號爲SUM
的Talk
和Hear
。 Talk
和Hear
是bit
字段。
下面給我一個獨特的名單Places
,所以我需要在Talk
和Hear
計數中添加。
var counts = from p in db.Places
join pp in db.ProfilePlaces on p.ID equals pp.PlaceID
group new { Place = p } by p.Display;
我覺得這樣的事情,但沒有任何運氣
var counts = from p in db.Places
join pp in db.ProfilePlaces on p.ID equals pp.PlaceID
group new { Place = p,
Talk = pp.Count(t => t.Talk == true),
Hear = pp.Count(t => t.Hear == true)
} by p.Display;
感謝您的幫助。
聽==見面?是一個錯字? – naveen
是的,已修復。對於那個很抱歉。 –