0

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?

Community
  • 1
  • 1
Manu
  • 1,013
  • 1
  • 11
  • 20
  • Try renaming either the `sex` property or the `personSex` property to something else, by appending something to the end of them. – Nick Larsen Dec 23 '11 at 04:18
  • @NickLarsen I changed the personSex property name, and what I get now is the same error message, with the new property name, that is: `The associated metadata type for type 'MyApp.Models.Person' contains the following unknown properties or fields: personSex_enum_based. Please make sure that the names of these members match the names of the properties on the main type.`. What I understand from that is that problem consists exactly in this newly-added property, which does not exist in the database-derived model (`the main type`). – Manu Dec 23 '11 at 16:53

0 Answers0