Mam niewielki problem z pozyskaniem Enity Framework 5 Enums do odwzorowania na kolumnę całkowitą w migracji. Oto co kod wygląda następująco:Niepoprawna wartość podczas zapisywania enum
[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; }
}
Migracja wygląda następująco:
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");
}
}
Jednak kiedy zapisać zmiany nie odzwierciedla ich w bazie danych.
var user = new UserProfile();
user.Status = UserProfile.StudentStatusType.Graduate;
user.FullName = "new";
user.UserName = "new";
users.UserProfiles.Add(user);
users.SaveChanges();
Baza:
----------------------------------------------------
|UserId | UserName | FullName | Status |
----------------------------------------------------
|1 | new | new | 1 |
----------------------------------------------------
Czy kierujesz system .NET Framework 4 przez przypadek, a nie program .NET Framework 4.5? – Pawel
Wybieram system .NET Framework 4.5. –