【发布时间】:2021-02-06 17:39:51
【问题描述】:
我有一些将复合键作为主键的实体。 我使用 fluentApi 配置它们来设置复合键,例如:
modelBuilder.Entity<EntityWithCompositeKey>().HasKey(entity => new { entity.Property1, entity.Property2});
但是当我想在添加新迁移后更新数据库时出现错误:
System.InvalidOperationException: To change the IDENTITY property of a column, the column needs to be dropped and recreated.
经过一番挖掘,我意识到这是因为 fluentApi 中的那些设置来设置复合键,我认为实体框架想要更改实体的主键来设置新的复合键,我得到这个错误......我是对的???我哪里做错了?
由于这个错误,我无法更新我的数据库,每次我需要删除迁移文件夹和数据库并重新创建它们以便进行新的更改时,随着我们越来越接近生产,这变得非常烦人。
我正在使用 Entity Framework 5rc1 和 Asp.Net Core 3.1
【问题讨论】:
标签: c# entity-framework asp.net-core entity-framework-core ef-fluent-api