我是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