Passphrase in Entity Framework 5 not added to database

I am having a problem getting enums to map to a database using an entity. I have set up a super base class to test my problem:

public class Person
{
    public int PersonId { get; set; }
    public Genders Gender { get; set; }

    public enum Genders
    {
        Female, Male
    }
}

      

In the context:

public DbSet<Person> Person { get; set; }

      

I am using MVC 4 to create a mapping. I am creating a new controller with Person as Model and my context as context. MVC forests create controller, views and database, but when I see a table named Person in DB with only one column - PersonId, but no column "Gender" .

More info: Using MVC 4 to target .Net 4.5 and using Entity Framework 5.0 (even double checking the dll version) and connecting to (LocalDb) \ V11.0.

I tried changing Genders to:

public enum Genders : Byte
{
    Female = 0, 
    Male = 1
}

      

I even tried moving Genders into a separate class, as one answer suggested .

I came across one MSDN article that sets up a class in the same way as mine and works, with the only difference that they used the console instead of MVC.

Did I miss something???

+3


source to share


1 answer


You must define an enum outside of any class. Don't put it in a class.



+7


source







All Articles