当前位置: 代码迷 >> ASP.NET >> 求教sql 转 linq to ef 的有关问题,高手帮帮忙.
  详细解决方案

求教sql 转 linq to ef 的有关问题,高手帮帮忙.

热度:2053   发布时间:2013-02-25 00:00:00.0
求教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)
}
  相关解决方案