dncuug/X.PagedList

Document that you have to order your IQueryable

GeeWee opened this issue · 2 comments

Is your feature request related to a problem? Please describe.
In the documentation you simply pass an IQueryable to the PagedList without any sort of keyselector. However if you e.g. pass an IQueryable from a database without any keyselector, then the results aren't guaranteed.

The generated SQL (For sql server) is as follows

SELECT [a].[WtgId], [a].[TimeOnUtc], [a].[Code], [a].[AlarmType], [a].[Controller], [a].[Guid], [a].[SourceId], [a].[StationId], [a].[Text], [a].[TimeOffLocal], [a].[TimeOffUtc], [a].[TimeOnLocal], [a].[Vendor], [a].[VendorData], [a].[Version], [a].[WindFarmId]
FROM [alarms] AS [a]
ORDER BY (SELECT 1)
OFFSET @__p_0 ROWS FETCH NEXT @__p_0 ROWS ONLY 

where ORDER BY (SELECT 1) doesn't actually enforce any ordering.

This means that if I use the same queryable multiple times, the results are non-deterministic. As the paginated list just seems to use skip & take, this means that the paginated list will be out of order, and you can get duplicated values while paginating through.

I think a keyselector should be forced if you don't pass in an IOrderedQueryable, so we're sure that we always have a working pagination.

maybe you should force orderby in your library when creating paginglist just before skip and take? is there any concerns doing so? it will actually fix the problem