I have a class called Reservation that has the properties StartDate and RoomNumber. Then I have a list Reservations in which I use Linq to find reservations that have conflicts (A conflict means that a reservation has the same room number and start date as other reservations in the list)
In the following code, I used the GroupBy method to find the duplicates from the list. But I need to return a Dictionary<> which I can not longer do because of the GroupBy() method. How can I access the Reservation class?
How can I return the Dictionary, because right now I can only access the date and number properties, not the Reservation class. Class main:
return Reservations.GroupBy(i => new {i.StartDate, i.RoomNumber}).Where(g => g.Count)>1).Select(group => new {
key=group.Key,
value=group.ToList()
}).Select(f => new Dictionary <Reservation, List<Reservation>> (f.key, f.value);
For example: if Reservation with Id=1 has conflicts with Reservations with Id=2 and with Reservation with Id=3 then my Dictionary will contain Reservation with Id=1 as key and a List containing the reservations in conflict (with Id 2 and 3)