You can group an anonymous object containing items that interest you:
var schedules = from program in _db.Programs join schedule in _db.Schedules on program.Id equals schedule.ProgramId join date in _db.ScheduleDates on schedule.Id equals date.ScheduleId
The above returns an IEnumerable<IGrouping> , where the key is an anonymous type with the properties Startdate and Enddate (both DateTime s), and the elements are anonymous types with Program , Schedule and Date elements. You can configure this to include only the parts you care about.
When used as objects, anonymous types implement the GetHasCode() and Equals tags, which consider them equal if each of their respective properties is equal (similar to the default equality for struct s, but compiled, rather than through reflection, to make it work better).
When used with other query providers (e.g. linq2sql, etc.). The supplier should be aware of this, and therefore pass the grouping to the database, although sometimes it is imperfect at the same time (it still works, but not all the work performed at the database level).
source share