Entity Framework: Get Distinct Result Set on Multiple Columns with Order By

I am creating a report based off of the following result set:

ef-distinct-multi-column

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();

Leave a Reply

Privacy Settings
Name Enabled
Cookies
We use Cookies to give you a better website experience.
x

We use cookies to ensure the best possible experience on our website. Detailed information on the use of cookies on this site is provided in our Privacy and Cookie Policy. You can also manage your preferences there.