I am trying to do something really simple. I want to use an Enum as column type in my Code First solution. I am using Entity Framework 5.0 Stable Release.
Consider my Enums wrapper class and Model:
public class Enums
{
public enum UserType
{
Bronze = 0,
Silver = 1,
Gold = 2,
Admin = 4
}
}
public class User
{
public int UserId { get; set; }
public string UserName { get; set; }
public Enums.UserType UserType { get; set; }
}
If I generate the database the column UserType is not generated. When I remove the ‘class wrapper’ around my Enum like this:
public enum UserType
{
Bronze = 0,
Silver = 1,
Gold = 2,
Admin = 4
}
public class User
{
public int UserId { get; set; }
public string UserName { get; set; }
public UserType UserType { get; set; }
}
It DOES gets generated! Is my first setup such an uncommon or ‘please do not’ approach?
I would like to hear some suggestions that are standardized or best practice and/or explanations why my first setup doesn’t work.
Nested types (be it enums, complex types or entities) are not supported by EF.