I have a database first model, where is a Person entity, like this:
public partial class Person
{
public System.Guid personID { get; set; }
public string firstName { get; set; }
public string lastName { get; set; }
public string sex { get; set; } // since in the DB it is char(1), default = 'F'
}
I defined a public enum for sex selection:
public enum Sex
{M, F}
which I want to use it to select the sex of the person and to render it as a radio button group.
I followed this solution: pass enum to html.radiobuttonfor MVC3 but couldn't make it work.
According to that answer, I added the RadioButtonForEnum extension, I extended my partial class with another property, like this:
public partial class Person
{
public System.Guid personID { get; set; }
public string firstName { get; set; }
public string lastName { get; set; }
public string sex { get; set; } // since in the DB it is char(1), default = 'F'
public Sex personSex { get; set; }
}
and changed my viewmodel and controller to use the enum.
Now I got the error:
The associated metadata type for type 'MyApp.Models.Person' contains the following unknown properties or fields: personSex. Please make sure that the names of these members match the names of the properties on the main type.
How can I fix this, since the model is derived from the database?