NHibernate Linq Group By fails to group properly in SQL Server

前端 未结 1 474
逝去的感伤
逝去的感伤 2021-01-11 17:15

I have the following LINQ query which uses NHibernate against a SQL Server backed repository...

var casesByCaseOwner = this.preGrantDetailRepository.All
   .         


        
1条回答
  •  渐次进展
    2021-01-11 18:12

    I found the answer finally...

         var casesByCaseOwner = this.preGrantDetailRepository.All
         .Where(x => x.CaseFileLocation.Id == cflId)
         .GroupBy(x => new { x.CaseOwner.Id, x.CaseOwner.Name })
         .Select(x => new StagSummaryForCfItem
         {
            Id = x.Key.Id,
            Description = x.Key.Name,
            NumberOfCases = x.Count(),
            UninvoicedNetFee = x.Sum(y => y.UninvoicedNetFee),
            UninvoicedDisbursement = x.Sum(y => y.UninvoicedDisbursement)
         }).AsEnumerable();
    
         return casesByCaseOwner;
    

    This works nicley, it turns out I need to project a new entity with the properties I want to group on.

    0 讨论(0)
提交回复
热议问题