1

I'm using the following grouping within my LINQ statement.

I have figured out how to obtain the maximum date from the 'notes' table, however am struggling to find an efficient way to find the 'NoteText' property of the same record (highlighted with ???? in both places)

group new { t1, notes } by new
{
    t1.Opportunity_Title
} into g

let latestNoteDate = g.Max(uh => uh.notes.Date)
let latestNote = g.Max(uh => uh.notes.NoteText) < needs to be latest note for record above ^

select new PipelineViewModel
{
    LastNoteDate = latestNoteDate,
    LastNote = latestNote,  ????
}).Take(howMany);
Nick
  • 5,844
  • 11
  • 52
  • 98

1 Answers1

2

Perhaps like this:

let latestNote = latestNoteDate == null ? null : 
                 g.First(x => x.notes.Date == latestNoteDate).NoteText
Magnus
  • 45,362
  • 8
  • 80
  • 118