Sort Data using Entity Framework

sometimes we need to sort data when working with entity sets. here is very simple yet powerful single line statement  that sorts data.

we are going to sort data using CustomerName Property. remember that “it” is a must.

//Ascending order
var data = context.Customers.OrderBy(“it.CustomerName ASC”);

//descending order
var data = context.Customers.OrderBy(“it.CustomerName DESC”);

// lets user this data
customerBindingSource.DataSource = data;

Advertisements

2 thoughts on “Sort Data using Entity Framework

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s