First Enum code not allowed in class "Enums"? (EF 5)

I am trying to make something very simple. I want to use the Enum column type in my Code First solution. I am using the stable version of Entity Framework 5.0.

Consider my Enum and Model wrapper class:

 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 a database, the UserType column UserType not be generated. When I remove the wrapper ' class around my Enum as follows:

 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; } } 

Created by DOES ! Is my first setup so unusual or “please stay away”?

I would like to hear some suggestions that are standardized or best practices and / or explanations of why my first setup does not work.

+4
source share
2 answers

Nested types (whether enumerations, complex types, or objects) are not supported by EF.

+1
source

I have never seen anyone use the wrapper class around Enum before. Of course, maybe I will not manage enough. :) I saw catch-all files that contained many Enum definitions inside the same namespace, but there never was a wrapper class. I don’t see the wrapper class adding anything.

As @Pawel said, nested types are not supported by EF. And that makes sense: if you create an internal type, but not an external type, what is the point of the external type?

+3
source

All Articles