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

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.