0
votes

So a slightly weird one that I can't find any cause for really.

My app is set up to basically run almost all queries through one standard method that handles things like querying against the local cache etc. So essentially the queries are all pretty standardised.

Then I have just one, with a strange orderby issue. The query includes a specific orderby clause, and if I run the query first time, the cache is checked, no results found, queries the remote data source, get data, all correct and ordered.

When I return to the page, the query is executed again, and the query is executed against the local cache, where it does find the data and returns it... the weird parts is the order is reversed. Bear in mind the parameters going in are exactly the same, the only difference is the query is executed with executeQueryLocally, and results are found, and returned (in the first query, it is still executed with executeQueryLocally, it's just that no results are found and it goes on to execute it remotely).

I really can't see any specific issue as to why the results are reversed (I say they are reversed, I can't actually guarantee that - they might just be unordered and happen to come out in a reversed order)

This isn't really causing a headache, it's just weird, especially as it appears to be only one query where this happens).

Thoughts?

1
Do you want Breeze to force ordering? If so, have you considered using an orderBy clause? Generally your view model should be in charge of sorting, ordering, etc... - PW Kad
Very sorry everyone, I mentioned orderby but forgot to make it clear that there was a specific orderby clause included in the query. So remember both queries are actually exactly the same, and therefore both include the same specific orderby classier, it's just that the first finds nothing in the local cache and ends up running on the server, whereas the second gets its results from the cache. - Adam
Are you saying that the "ordering" is not being performed in either the server query or the client query? - Jay Traband
The ordering is not performed, or at least not being performed as I would expect, on the client side (during the second query where the system makes use of executeQueryLocally). - Adam

1 Answers

0
votes

Server side queries and client side queries are not guaranteed to return results in any specific order UNLESS you have an "orderBy" clause specified. The reason that order may be different without the "orderBy" clause is that the data is being stored very differently on the server vs the client and unless a specific order is specified both will attempt to satisfy the query as efficiently as possible given the storage implementation.

One interesting side note is that per the ANSI 92 SQL standard, even your SQL database is not required to return data in the same order for the same query ( again unless you have an ORDER BY clause). It's just that it's very rare to see it happen.