工作我使用的数据库第一实体框架6.改变某些表在我的架构后进行时态表,我开始试图插入新的数据时,出现以下错误:实体框架不与时态表
Cannot insert an explicit value into a GENERATED ALWAYS column in table '<MyDatabase>.dbo.<MyTableName>. Use INSERT with a column list to exclude the GENERATED ALWAYS column, or insert a DEFAULT into GENERATED ALWAYS column.
看起来EF正试图更新由系统管理的PERIOD
列的值。
从EDMX文件中删除列似乎可以解决问题,但这不是一个可行的解决方案,因为每次从数据库重新生成模型时都会重新添加列。
我如何用实体框架核心做同样的事情? –
@AramGevorgyan - 您可以在属性上使用属性[DatabaseGenerated(DatabaseGeneratedOption.Computed)],或者使用Fluent API方法.ValueGeneratedOnAddOrUpdate() entity.Property(e => e.ValidFrom).ValueGeneratedOnAddOrUpdate(); [见这里](http://www.learnentityframeworkcore.com/configuration/data-annotation-attributes/databasegenerated-attribute)以供参考。 –
工作就像一个魅力! 'usings'如下'使用System.Data.Entity.Infrastructure.Interception; using System.Data.Entity.Core.Common.CommandTrees; using System.Data.Entity.Core.Metadata.Edm; using System.Collections.ObjectModel;' – mike123