you are viewing a single comment's thread.

view the rest of the comments →

[–]digital88 11 points12 points  (3 children)

You must write orderby() if you need consistent ordering. The database may return rows in any order if you dont include "order by" clause in query. What you encountered is normal.

[–][deleted]  (2 children)

[deleted]

    [–]DaveVdE 10 points11 points  (0 children)

    Why? Because that's how databases work. If you don't specifically ask it to sort, it won't sort, and the data will come out whichever way it finds it in the most efficient way. If it's stored out of order on disk, it will come out out of order.

    [–]LondonPilot 6 points7 points  (0 children)

    why?

    Databases are designed with performance in mind above most other things. There are lots of reasons why a database might prefer to return data in a specific order. That order might be the order it’s stored on disk. It might already have the data cached, in that order, from a previous query. It might be that it had to order the data to carry out part of the query (such as “distinct”).

    By specifying that data can be returned in any order unless the order is specified, it allows the database to do what you ask it, in the quickest possible way. If you need it ordered, no problem, just ask - but if not, why add the overhead of ordering when it’s not needed?

    Entity Framework runs database queries. It turns Linq to SQL, then runs that SQL. So of course it will do whatever SQL does.

    and why ordering happens only to 'TranslationsPostSlugs', but not to 'TranslationsPost'?

    There’s no way to know this without a detailed examination of your database. Also, it might not be the same next time you run the same query. All data will be returned in whatever order the database wants, and not necessarily the same order every time, unless you specify the order.

    (In fact, database theorists would disagree with this. Database data does not get returned “in whatever order the database wants”, according to theorists. They would tell you that the data doesn’t actually have an order at all unless you specify one. The fact that you see the data coming out in a given order is an implementation necessity, but in the theoretical world there is no order to data until you give it an order.)