A view returns duplicate or missing rows when paging
If you read a view window by window (next links, $skip), you find some rows twice and others not at
all.
Environment
Sets the service offers without a key: tables without a unique key and views for which SQL Server
reports no key that the view shows completely; every interface. $metadata shows whether a set has a
key (<Key>).
Cause
A window with an offset is repeatable only over a fixed order. The service adds a fallback sort order only from the set's key (see OData: keys); without a key there's none, and an invented sort order would look like a promise without being one. The service still offers the next link—without it, the caller would certainly stop after the first window; with it, the result is only possibly inaccurate.
Resolution
- Specify
$orderbyover columns that are unique together. - Or read in one window if the set stays under
Limits:MaxTop.
Verification
The sum of the rows read equals $count, and no key combination occurs twice.
Related topics
- HTTP: OData v4 (reference) — the key of a view