问题描述
我们将EF Core和SQL Server 2016用于.NET Core Web API.我正在评估时态表的使用及其对EF Core代码的影响.当我使用cmdline生成EF模型时,它将使用appstart,append和dbcontext
中的映射生成模型.当我执行插入/更新操作时,它们失败,提示无法更新这些列.我必须从模型和dbcontext
映射中删除appstart,end以使其起作用.我读到像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 anddbcontext mappings and updates/insert started working properly.
选项2:用属性如下.
option 2: decorate period columns withattributes as below.
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public DateTime StartTime { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public DateTime EndTime { get; set; }
这篇关于实体框架核心和SQL Server 2016时态表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!