I'm trying to use EF Core with Temporal tables - SQL Server
I found these extensions:
EntityFrameworkCore.TemporalTables.Extensions
Which looks very nice...
However, when I run this code:
var allItems = context.MyModel.Between(DateTime.MinValue, DateTime.UtcNow);
var listOfAllItems = allItems.ToList();
The second line throws
Microsoft.Data.SqlClient.SqlException: 'Invalid object name 'MyModel'.'
Am I doing something wrong? Or should I add some additional settings?!
Update: When I use simple LINQ
it works, so this example comes with results:
var allItems = context.MyModel.ToList();
I found this extension, which works perfectly, with no problems:
https://github.com/glautrou/EfCoreTemporalTable
So you can do the same, with the method AsTemporalBetween
:
var allItems = context.MyModel.AsTemporalBetween(DateTime.MinValue, DateTime.UtcNow);
var listOfAllItems = allItems.ToList();
And it retrieves all the records (From both tables).
There are also other methods available:
- AsTemporalAll()
- AsTemporalAsOf(date)
- AsTemporalFrom(startDate, endDate)
- AsTemporalBetween(startDate, endDate)
- AsTemporalContained(startDate, endDate)