Entity Framework: Select Distinct with Order By

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

Flot Line Chart

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

One Response

  1. hr August 31, 2016

Leave a Reply


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. Further instruction on how to disable our cookies can be found there.