Since you need to interpret each entry twice - for example, SentTo and SentFrom , the query becomes a bit complicated:
var res = ecml .SelectMany(m => new[] { new { User = m.SentFrom, m.SendDate } , new { User = m.SentTo, m.SendDate } }) .GroupBy(p => p.User) .Select(g => new { User = g.Key , Last = g.OrderByDescending(m => m.SendDate).First() });
The key trick is in SelectMany , which makes each ChatMessage element into two anonymous elements - one that connects the SentFrom user to SendDate , and one that connects the SentTo user from the same date.
Once you have both entries in an enumerable, the rest is simple: you group the user, and then apply the request from your message to each group.
source share