我将Entity Framework 5 Enums映射到迁移中的整数列时遇到一些困难.这是代码的样子:
[Table("UserProfile")]
public class UserProfile
{
public enum StudentStatusType
{
Student = 1,
Graduate = 2
}
[Key]
public int UserId { get; set; }
public string UserName { get; set; }
public string FullName { get; set; }
public StudentStatusType Status { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
迁移看起来像这样:
public partial class EnumTest : DbMigration
{
public override void Up()
{
AddColumn("UserProfile", "Status", c => c.Int(nullable: false, defaultValue:1));
}
public override void Down()
{
DropColumn("UserProfile", "Status");
}
} …Run Code Online (Sandbox Code Playgroud) c# entity-framework code-first ef-migrations entity-framework-5