Using entity framework, "order by Col1, Col2."

.net c# entity-framework linq

Question

I need to order by 2 columns using the entity framework.

How is that done?

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

i.e

SELECT * FROM Foo ORDER BY Col1, Col2
1
112
4/21/2019 1:43:57 PM

Accepted Answer

Try OrderBy(x => x.Col1).ThenBy(x => x.Col2). It is a LINQ feature, anyway, not exclusive to EF.

235
11/9/2009 12:09:07 PM

Popular Answer

Another way:

qqq.OrderBy(x => new { x.Col1, x.Col2} )


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow