1

I know the Entity Framework, as of version 5, supports enums. As this article states:

In Entity Framework, an enumeration can have the following underlying types: Byte, Int16, Int32, Int64 , or SByte.

However, this usually results in mapping enums to numbers, which is their numerical order in the code. If you insert a new value for this enum anywhere except at the end, this will invalidate your database.

Maybe it's a question of how often you do this versus how often you change the string value of your enum, but I want to know: is it possible to tell EF to map the string value and not the int value?

say if I have the following enum:

public enum Gender 
{
    Male,
    Female
}

I want my database to contain the values "Male" or "Female" and not 0 or 1.

4

0 回答 0