Can anyone help?
I have 1 class, basically it contains members and inside this class is List.
The members that I have on the list ... So basically this happens as if
I have 2 members and each member has several sessions.
I only want to return each member with 1 session.
I fulfilled the LINQ query, but of course it does not work ...
I think I need to make an independent connection, any ideas?
Mostly my mistake: m does not exist in my self-join subquery.
var sessions = from m in this.members join s in ( from se in m.Sessions group se by se.Name into g select new {Name = g.Key, SessioEndTime = g.Max(a=>a.SessioEndTime)} ) on m.Name equals s.Name select new { MemberName = m.Name, SessionTime = s.SessioEndTime}
I would be grateful for any feedback that anyone has.
Thanks in advance.
EDIT
Ok, I managed to do it as follows, but is this the best way?
var sessions = from m in this.members let sn = m.Sessions.OrderByDescending(a => a.SessionEndTime).FirstOrDefault() select new { MemberName = m.Name, SessionTime = sn.SessioEndTime}
This sn method contains 1 entry, but I have access to all properties ...
But is this the best way to do this with LET?
Thanks.
linq self-join linq-to-objects linq-to-sql
Martin
source share