0

我创建了有史以来最复杂的 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
      });
4

1 回答 1

0

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

于 2013-06-18T23:31:51.153 回答