I have a “little” problem with ASP.NET MVC 3 and enum:
My Person Model:
namespace AcTIV.Models
{
public enum Sex { Male, Female };
public class Person
{
public int PersonID { get; set; }
public string Name { get; set; }
public Sex Sexo { get; set; }
}
}
My Initializer:
namespace AcTIV.DAL
{
public class AcTIVInitializer : DropCreateDatabaseAlways<AcTIVContext>
{
protected override void Seed(AcTIVContext context)
{
var persons = new List<Person>
{
new Person { Name = "Mary Lee", Sexo = Sex.Female }
};
persons.ForEach(s => context.Persons.Add(s));
context.SaveChanges();
}
}
}
So far, so good. My Watch displays the correct values.
persons[0].Name = "Mary Lee"
persons[0].Sexo = Female
Now, my Person Controller:
namespace AcTIV.Controllers
{
public class PersonController : Controller
{
private UnitOfWork unitOfWork = new UnitOfWork();
public ViewResult Index()
{
Person person = unitOfWork.PersonRepository.GetByID(1); //Just for test
//return View(unitOfWork.PersonRepository.Get().ToList());
}
}
}
Here my Watch displays the wrong enum value:
person.Name = "Mary Lee"
person.Sexo = Male
What am I doing wrong?
— SOLVED —
The Answer is on another stackoverflow post:
How is interpreted an enum type with EF Code First
Are you using EF4.3? I believe
enumsupport is only available in EF5