Search code examples
entity-framework-6sql-server-2008r2-express

Data from SQL view in entity collection are not sorted


I have a simple SQL view with 2 columns. First is the primary key, which is an nvarchar, and the second is an int. View is ordered by the int column. When I load data using EF, data is not sorted how is specified in SQL. What do I need to do to receive correctly sorted data?


Solution

  • ORDER BY is effectively ignored in a view. You need to specify ORDER BY in the actual query you use against the view. See the following for an explanation.

    https://dba.stackexchange.com/questions/66353/why-is-the-order-by-clause-in-a-view-ignored-as-soon-as-its-called-with-a-where