我是EF5 Code First的新手,在開始工作之前,我正在修改概念驗證。EF5代碼優先 - 遷移列類型
我已初步建立,看上去像
public class Person {
public int Id { get; set; }
public string FirstName { get; set;}
public string Surname {get;set;}
public string Location {get;set;}
}
模型,並利用我有點MVC應用程序,我貼在上面添加幾個記錄。
現在我想的位置列更改爲枚舉,是這樣的:
public class Person {
public int Id { get; set; }
public string FirstName { get; set;}
public string Surname {get;set;}
public Locations Location {get;set;}
}
public enum Locations {
London = 1,
Edinburgh = 2,
Cardiff = 3
}
當我添加新的遷移,我得到:
AlterColumn("dbo.People", "Location", c => c.Int(nullable: false));
但是當我運行更新數據庫I得到一個錯誤
Conversion failed when converting the nvarchar value 'London' to data type int.
在運行alter語句之前,遷移中是否有方法來截斷表?
我知道我可以打開數據庫並手動執行它,但有沒有更智能的方法?
我建議在他們看到如果轉換是自動實體框架下一些此頁面上的答案之前處理過類似的崗位開發。例如,我發現它處理字符串和小數之間的轉換,然後再次返回,沒有我的幫助 - 添加遷移生成的遷移工作正常。顯然,在將其應用於生產之前,先在本地/測試數據庫上嘗試一下。 – pipedreambomb 2016-12-19 14:33:14