1

我想用 Linq 写这个简单的查询:

select issuercode,securitycode,dataprocessingflag,COUNT(issuercode) as cnt 
from cmr_invhdr
where ProcessedLike <> 'STMNT ONLY'
group by issuercode,securitycode,dataprocessingflag
order by Issuercode

我尝试了以下代码,但出现此错误(DbExpressionBinding 需要一个带有集合 ResultType 的输入表达式。参数名称:输入):

 var lstCMRInvHdrNips = (from r in e.CMR_INVHDR
                         where r.ProcessedLike != "STMNT ONLY"
                         select new { 
                                        r.IssuerCode, 
                                        r.SecurityCode, 
                                        CountofIssuerCode = r.IssuerCode.Count(),
                                        r.DataProcessingFlag 
                                    }
                         ).GroupBy(x => 
                                       new { 
                                               x.IssuerCode, 
                                               x.SecurityCode, 
                                               x.DataProcessingFlag, 
                                               x.CountofIssuerCode 
                                           }
                                   ).OrderBy(x => x.Key.IssuerCode).ToList();
4

1 回答 1

2

issuercode一次按此字段分组时是否有任何意义?当按字段分组时,COUNT它将始终为 1。

可能您不应该在单独的语句中分组issuercode和计算它:GroupBySelect

var result = e.CMR_INVHDR
              .Where(r => r.ProcessedLike != "STMNT ONLY")
              .GroupBy(r => new { r.SecurityCode, r.DataProcessingFlag })
              .Select(r => new 
              { 
                  Value = r.Key, 
                  IssuerCodesCount = r.GroupBy(g => g.IssuerCode).Count() 
              })
              .ToList();
于 2013-08-29T02:15:39.173 回答