Entity Framework Core 和 SQL Server 2016 时态表 [英] Entity Framework Core and SQL Server 2016 temporal tables
问题描述
我们将 EF Core 和 SQL Server 2016 用于我们的 .NET Core Web API.我正在评估时态表的使用及其对 EF Core 代码的影响.当我使用 cmdline 生成 EF 模型时,它会在 dbcontext
中生成带有 appstart、append 和映射的模型.当我插入/更新时,他们说这些列无法更新.我不得不从模型中删除 appstart、end 和 dbcontext
映射以使其工作.我读到像 EF 6.x 这样的 EF Core 中还没有拦截功能.
We are using EF Core and SQL Server 2016 for our .NET Core Web API. I am evaluating use of temporal tables and its impact on EF Core code. When I generate the EF model using cmdline then it generates model with appstart, append and mappings in dbcontext
. When I do insert/update they fail saying these columns cannot be updated. I had to remove appstart, end from model and dbcontext
mapping to make it work. I read there is no interception capability yet in EF Core like EF 6.x.
请就任何更好的解决方案提出建议.
Please advise about any better solutions for this.
推荐答案
我尝试了以下选项,它们都有效.
I tried below options and they are working.
选项 1:删除 appstart,从实体和附加字段dbcontext 映射和更新/插入开始正常工作.
option 1: removed appstart, append fields from entities and dbcontext mappings and updates/insert started working properly.
选项 2:用属性如下.
option 2: decorate period columns with attributes as below.
<小时>
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public DateTime StartTime { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public DateTime EndTime { get; set; }
这篇关于Entity Framework Core 和 SQL Server 2016 时态表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!