LINQ Consultation - Get the latest key registration

advertisements

I have the following query which returns me a list of guests along with a list of RSVPs. However since a user can have multiple RSVPs per event, I would only like to get the latest. RSVPs table has a submitted date column.

from guest in Guests
                join rsvp in RSVPs.Where(o => o.EventID == "1234")
                on guest.UserName equals rsvp.UserName into sr
                from x in sr.DefaultIfEmpty()
                select new
                {
                     guest,
                    x
                }


Order by the date and take 1:

(from guest in Guests
            join rsvp in RSVPs.Where(o => o.EventID == "1234")
            on guest.UserName equals rsvp.UserName into sr
            from x in sr.DefaultIfEmpty()
            orderby x.RSVPDate desc
            select new
            {
                 guest,
                x
            })
.Take(1);