Entity Framework: Select Distinct with Order By | Quisitive
Entity Framework: Select Distinct with Order By
June 24, 2015
Quisitive
Read our blog.

I am creating a Flot Line Chart in .Net based on the following Entity Framework result set.

I want to get a distinct list of the report categories in alphabetical order to use as a control group.

Flot Line Chart

Entity Framework provides an easy Distinct() method to retrieve distinct values from a data set, but it wasn’t completely obvious to me how to make sure that it was given to me in ascending order.

Turns out, it’s pretty easy.

List<string> categories = reportSummary.Select(m => m.CategoryName).Distinct().ToList();