Stacker
Stacker

Reputation: 8237

EF 4.1 CodeFirst and Enumerations

I have a class like that:

public class Customer
{
  public string Name {get; set; }
  public enumGender Gender {get; set; }
}

public enum enumGender 
{
    Male,
    Female
}

I`m trying to use this as entity and i want to map gender to the database as int, right now gender of course doesn't get mapped at all.

any idea how to do that

thanks in advance.

Upvotes: 0

Views: 819

Answers (2)

mandreko
mandreko

Reputation: 1796

Another option, would be upgrading to the June CTP of Entity Framework, which now supports enums. http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=26660

This has been working wonderfully for me.

Upvotes: 1

Stacker
Stacker

Reputation: 8237

this is how i got over it....

public class Customer
{
  public string Name {get; set; }
        public int gender { get; set; }
        public enumGender Gender
        {
            get { return (CodeFirstEF.Gender) gender; }
            set { gender = (int) value; }
        }
}

public enum enumGender 
{
    Male,
    Female
}

Upvotes: 3

Related Questions