LInq到实体选择新的计数在哪里

本文关键字:在哪里 实体 选择 LInq | 更新日期: 2023-09-27 18:18:54

我创建了有史以来最复杂的linq查询,但仍然没有完全满足我的需要。从这个查询中,我需要知道EventStudents表中有多少相关的学生具有DateDeleted == null。所以,StudentCount = ev。EventStudents -其中DateDeleted == null . count()。有人能帮帮忙吗?

var inf = (from ev in db.Events
       where (ev.StartDate >= beginDate && ev.StartDate <= endDate)
        && ev.DeletedDate == null
       orderby ev.StartDate descending
       select new
      {
          EventID = ev.EventID,
          EventTitle = ev.Title,
          EventDate = ev.StartDate,
          StudentCount = ev.EventStudents.Count(),
          CreatedUsername = ev.CreatedUsername
      }).AsEnumerable().Select(x => new
      {
          EventID = x.EventID,
          EventTitle = x.EventTitle,
          EventDate = x.EventDate,
          StudentCount = x.StudentCount,
          CreatedUsername = x.CreatedUsername,
          CreatedFullname = sortedUserDictionary.Where(u => u.Value == x.CreatedUsername)
          .Select(f => f.Key)
          .FirstOrDefault() ?? x.CreatedUsername
      });

LInq到实体选择新的计数在哪里

ev.EventStudents.Count()改为ev.EventStudents.Count(es => es.DateDeleted == null)