【发布时间】:2015-12-19 00:17:51
【问题描述】:
我正在使用实体框架代码优先方法。当我将新表添加到我的上下文中时,我能够使用 Add-Migration 自动检测。但是,当我在其中一个模型上更改外键时,Add-Migration 无法检测到更改并生成代码来更新外键。
这是我的模型
public class PhoneInfo
{
[Key]
[Column(Order = 2)]
public String ID { get; set; }
[Required]
[Key]
[ForeignKey("Contact"), Column(Order = 1)]
public String UserID { get; set; }
[Required]
[Key]
[ForeignKey("Contact"), Column(Order = 0)]
public String ContactID { get; set; }
public String Value { get; set; }
public DateTime LastChanged { get; set; }
public String Type { get; set; }
public int Order { get; set; }
public bool IsDeleted { get; set; }
public DateTime DeletedDate { get; set; }
public virtual Contact Contact { get; set; }
}
我正在更新下面的 Column(Order = 1)
[ForeignKey("Contact"), Column(Order = 1)]
有什么方法可以让 Add-Migration 自动生成更新数据库所需的代码?
【问题讨论】:
标签: entity-framework ef-code-first foreign-keys entity-framework-6 entity-framework-migrations