views:

593

answers:

2

I plan on using this in a subquery but can't figure out the correct syntax to translate the following query into LINQ:

select ChapterID, min(MeetingDate)
from ChapterMeeting
group by ChapterID
+5  A: 
var query = myDataContext.ChapterMeeting
  .GroupBy(cm => cm.ChapterID)
  .Select(g => new {
      g.Key,
      MinMeetingDate = g.Min(cm => cm.MeetingDate)
  });
David B
+5  A: 

Well, David beat me to it, but in case you wanted to see it with the "comprehension" syntax:

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)});
Daniel Pratt
Could you make a change edit to your answer (to "group cm by cm.ChapterID into cmg")? I can't make an edit yet :)
Even Mien
Ah, good catch. That'll teach me to free-hand it ;-)
Daniel Pratt
LINQ-to-SQL version?
Daniel Pratt