Most of the time, as you retrieve your data from the database, you need to present it in a certain order. This order can include one or more fields and can be ascending, going from the smallest to the largest value, or descending, going from the largest to the smallest. You will find the sorting query syntax quite familiar, if you are accustomed to writing SQL queries. The following example will sort the person data on the last and first names of a person in ascending order. We are also going to combine filtering with sorting to illustrate how these two concepts work together in a single query, as shown in the following code snippet:
var query = from person in context.People where person.IsActive orderby person.LastName, person.FirstName select person; var methodQuery = context.People .Where(p => p.IsActive) .OrderBy(p => p.LastName) .ThenBy(p => p.FirstName);
The first query uses the query syntax and the second...