"Order Col1, Col2" using entity structure

I need to order in 2 columns using the entity infrastructure.

How it's done?

return _repository.GetSomething().OrderBy(x => x.Col1 .. Col2)? 

ie

 SELECT * FROM Foo ORDER BY Col1, Col2 

/ M

+67
c # linq entity-framework
Nov 09 '09 at 12:04
source share
4 answers

Try OrderBy(x => x.Col1).ThenBy(x => x.Col2) . Anyway, this is a LINQ function, not just for EF.

+131
Nov 09 '09 at 12:09
source share

Another way:

 qqq.OrderBy(x => new { x.Col1, x.Col2} ) 
+31
Oct 24 '13 at 15:34
source share

Try: OrderBy (x => x.Col1) .ThenBy (x => x.Col2)

Or for Descending try: OrderByDescending (x => x.Col1) .ThenByDescending (x => x.Col2)

+6
Aug 30 '15 at
source share

Please note that this will not work with the Telerik network or any other Telerik DataSource component. Although it uses a pre-filtered IQueryable, sorting is always done automatically, since the last step effectively overrides the sorting settings.

You need to follow: Specifying default sorting in the grid

-one
Feb 10 '17 at 9:34 on
source share



All Articles