Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting data using EF DbSet [closed]

Is there a way to pass an order by clause to a DbSet class in EF?

I'm using C#

like image 426
Carlos Blanco Avatar asked May 20 '11 15:05

Carlos Blanco


2 Answers

I am not sure how to do that from DbSet, but you can do this from DBContext by getting access to the IQueryable

private readonly DbContext context;
...
context.Set<T>().OrderBy(item => item.Property)
like image 195
oleksii Avatar answered Oct 19 '22 21:10

oleksii


What about using .OrderBy directly on the Entity?

db.Employees.OrderBy(p => p.Id);
like image 4
vapcguy Avatar answered Oct 19 '22 20:10

vapcguy