SQL到LINQ转换错误:DISTINCT Agregate计数无法转换为LINQ

时间:2016-02-11 12:16:44

标签: c# sql entity-framework linq

我有一个SQL查询,我正在尝试将其转换为LINQ。但是当我这样做时,我收到了这个错误:

  

SQL无法转换为LINQ:DISTINCT Agregate计数无法转换为LINQ

SELECT 
ST_CN_NO,
DN_DT,
count(ST_CN_NO) as totlines,
count(distinct LOC_CODE) as totloc,
sum(SN_QTY)as totscnqty,
sum(SAP_QTY) as totmpqty
from physical_count 
where 1=1  
group by ST_CN_NO,DN_DT  
order by physical_count.ST_CN_NO 

那么,如何将count(distinct LOC_CODE)转换为LINQ?有没有办法这样做?

这是我的LINQ查询,无需添加count(distinct LOC_CODE)

from t in db.PHYSICAL_COUNT
where
  1 == 1
group t by new {
  t.ST_CN_NO,
  t.DN_DT
} into g
orderby
  g.Key.ST_CN_NO
select new {
  ST_CN_NO = (Int32?)g.Key.ST_CN_NO,
  g.Key.DN_DT,
  totlines = (Int64?)g.Count(),
  totscnqty = (Int32?)g.Sum(p => p.SN_QTY),
  totmpqty = (Int32?)g.Sum(p => p.SAP_QTY)
}

0 个答案:

没有答案