T-SQL查询:
select
PRODUCT_ID, PRODUCT_NAME.NAME, SUM(SALES_PRICE) as PRODUCT_SALES
from SALES_PRODUCT_DETAILS
join PRODUCT_NAME on PRODUCT_NAME.ID = SALES_PRODUCT_DETAILS.PRODUCT_ID
where
SALES_ID in
(select SALES_ID
from SALES
where SALES_DATE >= '2011-11-13' and SALES_DATE <= '2011-11-16')
group by
PRODUCT_ID, PRODUCT_NAME.NAME
对此,等效的LINQ查询是什么?
答案 0 :(得分:1)
我认为这样的事情可以解决问题。
from s in SALES_PRODUCT_DETAILS
join p in PRODUCT_NAME on s.PRODUCT_ID equals p.ID
where SALES.Any(sales =>
sales.SALES_DATE >= new DateTime(2011, 11, 13) &&
sales.SALES_DATE <= new DateTime(2011, 11, 16) &&
sales.SALES_ID == s.SALES_ID)
group s by new { s.PRODUCT_ID, p.NAME } into g
select new
{
g.Key.Name,
g.Key.PRODUCT_ID,
PRODUCT_SALES = g.Sum(x => x.SALES_PRICE)
}