日期:2014-05-20  浏览次数:20867 次

求一条Sql翻译成Linq To Entity的写法

SELECT 
CONVERT(varchar(6), ActualSendTime,112),
COUNT(1),
SUM(a.ReceivablePrice),

COUNT(distinct customerid)

FROM Delivery a
WHERE OrderStatusID=5
group by  CONVERT(varchar(6), ActualSendTime,112) 


COUNT(distinct customerid) 这句该怎么翻译成Linq to entity?
LINQ entity

------解决方案--------------------
var query=from a in Delivery.ToList()
          where a.OrderStatusID==5
          group a by a.ActualSendTime.ToString("yymmdd") into g
          select new 
          { 
            Time=g.Key,
            Count=g.Count(),
            price=g.Sum(x=>x.ReceivablePrice),
            cid=g.Select(x=>x.customerid).Distinct().Count()
          }