我有这堂课:
public class HabitDo{
public int? HabitId { get; set; }
virtual public Habit Habit { get; set; }
public int DoId { get; set; }
virtual public Do Do { get; set; }
public string Restriction { get; set; }
public int? ObjectiveId { get; set; }
public Objective Objective { get; set; }
public virtual ICollection<DoObjective> Objectives { get; set; }
}
该表很好,但随后我从代码中删除了 Objective 属性:
public class HabitDo{
public int? HabitId { get; set; }
virtual public Habit Habit { get; set; }
public int DoId { get; set; }
virtual public Do Do { get; set; }
public string Restriction { get; set; }
public virtual ICollection<DoObjective> Objectives { get; set; }
}
当从管理器控制台调用 update-database 时,EF 会重命名 ObjectiveId 列而不是删除它:
EXECUTE sp_rename @objname = N'HabitDoes.ObjectiveId', @newname = N'Objective_Id', @objtype = N'COLUMN'
任何线索为什么会发生这种情况?