【发布时间】:2017-02-15 10:56:27
【问题描述】:
我有这个实体:
public class GWDetail: Entity
{
public int? GWNR { get; set; }
public double? PRNR { get; set; }
public double? GWO { get; set; }
public double? GWU { get; set; }
}
使用复合 PK 映射
// Primary Key
HasKey(t => new { t.PRNR, t.GWNR });
并想将其更改为:
public class GWDetail: Entity
{
public int? GWNR { get; set; }
public int? PRNR { get; set; } // change from double to int !!
public double? GWO { get; set; }
public double? GWU { get; set; }
}
和
// Primary Key
HasKey(t => t.Id)
我已经创建了 add-migration 脚本并应用了 update-database 但得到:
错误号:5074,状态:1,类:16 对象“PK_dbo.GWDetail”取决于列“PRNR”。 ALTER TABLE ALTER COLUMN PRNR 失败,因为一个或多个对象访问此列。
GWDetail 还没有任何记录。但是有一个父表通过 GWNR 与它具有 1:n 关系。父表有记录。
有人可以帮我解决这个问题吗? 谢谢和问候,马努
【问题讨论】:
标签: asp.net-mvc-4 entity-framework-6 entity-framework-migrations