Using LinQ to group a set of data by something is quite straightforward.
In the example below I am returning a list of bookings, which is very flat. I wanted to group the data returned by the BookingID
Using group on BookingID, I am able to rearrange the data to "group" sets of data that relate to a specific booking. Brilliant!
var bkgs = dal.GetBookings();var distinctbkgs = (from x in bkgsgroup x by x.BookingID into xxselect new{Booking = xx.First(),RelatedBookings = xx.ToList()}).ToList();
No comments:
Post a Comment