Entity Framework: Get Distinct Result Set on Multiple Columns with Order By | Quisitive
General Quisitive gradient background
Entity Framework: Get Distinct Result Set on Multiple Columns with Order By
June 24, 2015
Quisitive
Read our blog.
Catapult is now Quisitive-02

I am creating a report based on the following result set:

I wanted to get a unique set of weeks from the control group, but I also wanted to retrieve whether the week is an actual vs. a forecast.

Turns out it’s pretty easy:

public List<WeeklyUtilizationHistoryAndForecast> ReportSummary = businessService.GetWeeklyUtilizationHistoryAndForecast(isCache, ParamUserId, ParamStartWeek, ParamEndWeek, ParamBusinessUnitId, ParamIncludeTimeOff);
public List<WeeklyUtilizationHistoryAndForecast> Weeks = ReportSummary.OrderBy(m => m.WeekDisplay).DistinctBy(m => new { m.WeekDisplay, m.IsActual }).ToList();