用lambda表达式写分组查询的示例

时间:2021-04-01 20:11:44

需要完成的查询逻辑:查询A表中根据CertificateDelayApplyRecordId 分组,每条记录算8个课时,查询出每个CertificateDelayApplyRecordId已经学习了的课时,代码如下:

//线下课时 一次算8课时
var offLineClassHourQueryable = uow.Biz_ContinueEducationTrainSignRecord.GetAll().Where(p => p.SignBackPhotoPath.Length > 0)
      .GroupBy(o => o.CertificateDelayApplyRecordId).Select(o => new
    {
      CertificateDelayApplyRecordId = o.Key,
      ClassHour = o.Count() * 8
    });