entity-framework-rcerda

Entity Framework: Select Distinct with Order By

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

 ef_distinct_sort_rcerda

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

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