问题描述
我正在尝试将 EF Core 与临时表一起使用 - SQL Server我找到了这些扩展:EntityFrameworkCore.TemporalTables.Extensions
看起来很不错...
I'm trying to use EF Core with Temporal tables - SQL ServerI 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();
第二行抛出Microsoft.Data.SqlClient.SqlException: '无效的对象名称'MyModel'.'
我做错了吗?或者我应该添加一些额外的设置?!
Am I doing something wrong?Or should I add some additional settings?!
更新:当我使用简单的 LINQ
时它可以工作,所以这个例子有结果:
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
所以你可以用 AsTemporalBetween
方法做同样的事情:
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).
还有其他可用的方法:
- AsTemporalAll()
- AsTemporalAsOf(date)
- AsTemporalFrom(startDate, endDate)
- AsTemporalBetween(startDate, endDate)
- AsTemporalContained(startDate, endDate)
这篇关于如何使用 EntityFrameworkCore.TemporalTables.Extensions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!