Skip to content

Every version: AllVersions ​

Show me this policy's whole history.

cs
var timeline = await db.Policies
    .AllVersions()
    .Where(p => p.Id == policyId)
    .ToListAsync(); // newest first

AllVersions() reads from the history table and returns every stored version: one per insert and one per update. There is no period filter; this is the full timeline, not a point in time.

  • Rows come back newest first, by valid_from descending. Your own OrderBy or OrderByDescending replaces that order; a trailing ThenBy keeps newest first as the primary order.
  • Deletes are not versions. A deleted policy's timeline ends at the version that was current when it was deleted. To see the delete itself, when and by whom, use History<T>.

Composing ​

Like AsOf, it must be the first operator on the query, and everything after it composes into one SQL statement:

cs
var premiumsEverCharged = await db.Policies
    .AllVersions()
    .Where(p => p.Id == policyId)
    .Select(p => p.Premium)
    .Distinct()
    .ToListAsync();
The generated SQL

For a filter on Status (from Hindsight's test suite). operation <> 3 excludes tombstones:

sql
SELECT p.id, p.metadata, p.number, p.premium, p.status, p.tags
FROM policies_history AS p
WHERE p.operation <> 3 AND p.status = 'Active'
ORDER BY p.valid_from DESC

AllVersions returns entity snapshots only. When you also need each version's period or change context, use History<T>.

Released under the MIT License.