日期:2014-05-17  浏览次数:20440 次

求教sql 转 linq to ef 的问题,高手帮帮忙...
select a.purchase_code,a.staff_id,sum(b.price)
 from purchase a,purchase_product b where a.purchase_id=b.purchase_id
 group by a.purchase_code,a.staff_id

转成 linq to ef

from a in _dbo.Purchases
from b in _dbo.PurchaseProducts
where a.Purchase_ID == b.Purchase_ID
.
.
.

后面的groupby 和select 中的sum 不会写,哪位高手帮帮忙啊,在线等啊...

------解决方案--------------------
from a in _dbo.Purchases
from b in _dbo.PurchaseProducts
where a.Purchase_ID == b.Purchase_ID
group a by new{purchase_code=a.purchase_code,staff_id=a.staff_id} into g
select new
{
purchase_code=a.purchase_code,
staff_id=a.staff_id,
sum=g.sum(g=>b.price)
}