22

我计划在子查询中使用它,但无法找出将以下查询转换为 LINQ 的正确语法:

select ChapterID, min(MeetingDate)
from ChapterMeeting
group by ChapterID
4

2 回答 2

37
var query = myDataContext.ChapterMeeting
  .GroupBy(cm => cm.ChapterID)
  .Select(g => new {
      g.Key,
      MinMeetingDate = g.Min(cm => cm.MeetingDate)
  });
于 2009-03-17T13:46:41.340 回答
15

好吧,艾米打败了我,但如果你想用“理解”语法来查看它:

var q = (
    from cm in context.ChapterMeeting
    group cm by cm.ChapterID into cmg
    select new {
        ChapterID = cmg.Key,
        FirstMeetingDate = cmg.Min(cm => cm.MeetingDate)});
于 2009-03-17T13:52:46.257 回答