【发布时间】:2013-09-07 08:31:30
【问题描述】:
我有一个带有字符串属性的实体,我需要将其外部化到另一组实体:
public class MyEntity
{
public int Id { get; set; }
public string FavoriteColor { get; set; }
}
我想把它改成:
public class MyEntity
{
public int Id { get; set; }
public Color FavoriteColor { get; set; }
public int FavoriteColorId { get; set; }
}
public class Color
{
public int Id { get; set; }
public string Name { get; set; }
}
如果我创建一个迁移,它会在 db 中创建新的“Color”表,然后将新列添加到“MyEntity。如何确保不会丢失所有作为字符串存在的数据” MyEntity”?我尝试在迁移中加载 DbContext 以根据“MyEntity”中的字符串数据创建新的“Color”实体,但它存在问题,因为它检测到模型与当前架构不同步。
【问题讨论】:
标签: c# entity-framework entity-framework-migrations