0

コンプライアンスと非コンプライアンスの数を取得する必要があるクエリがあります

これがlinqに変換するために必要なSQLバージョンです...

 select ScheduleClause,
    COUNT(case Compliance 
            when 1 then 1 end) Compliance,
    Count(case Compliance
            when 0 then 1 end) NonCompliance
 from Compliance_RiskRegisterEntry cr
 where cr.RiskRegisterTypeId = 1 and Auditor = 5508 and MONTH(AuditDate) = 10 and           YEAR(AuditDate) = 2013
group by ScheduleClause

このlinqクエリを試してみましたが、別の結果が得られました

 compliance
     .GroupBy(x => new
     {
       x.ScheduleClause, x.Compliance
     })
     .Where(x => x.Key.Compliance == 1)
     .Select(x => new RiskRegisterCompliancePerCategoryDto
         {
             ScheduleClause =  x.Key.ScheduleClause,
             Compliant = x.Key.Compliance == 1 ? 1 : 0,
             NonCompliant = x.Key.Compliance == 0 ? 1 : 0,
             GrandTotal = x.Count()
          }).ToList();
4

2 に答える 2

0
    compliance
         .Where(p=> p.RiskRegisterTypeId = 1 && p.Auditor = 5508 && 
                    SqlFunctions.DatePart("MM", p.AuditDate) = 10 &&
                    SqlFunctions.DatePart("yy", p.AuditDate) = 2013)
         .GroupBy(x => x.ScheduleClause)
         .Select(x => new RiskRegisterCompliancePerCategoryDto
             {
                 ScheduleClause =  x.Key.ScheduleClause,
                 Compliant = x.Key.Compliance == 1 ? 1 : 0,
                 NonCompliant = x.Key.Compliance == 0 ? 1 : 0,
                 GrandTotal = x.Count()
              }).ToList();
于 2013-10-20T15:33:51.913 に答える