实体框架核心和SQL Server 2016时态表 [英] Entity Framework Core and SQL Server 2016 temporal tables

查看:112
本文介绍了实体框架核心和SQL Server 2016时态表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们将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. 选项1:删除了appstart,从实体附加字段并 dbcontext映射和更新/插入开始正常工作.

  1. 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; } 

这篇关于实体框架核心和SQL Server 2016时态表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆