As mentioned earlier, EF5 has explicit support for Enums, but if you cannot switch to it for any reason, the approach I took may work for you.
In this example, let's say that the table is called βEmail,β and we have a column called βPriority.β Set the column as int, as usual. Then, in your entities project, create an enumeration class that will map to your int values:
public enum EmailPriorityEnum { Now = 100, Soon = 1000, Whenever = 10000 }
Finally, in the project of your entities, create a file with a partial class that matches your object and manually map it by enumeration:
public partial class Email { public EmailEnums.EmailPriorityEnum EmailPriority { get { return (EmailEnums.EmailPriorityEnum)Priority; } set { Priority = (int)value; } } }
From there, your code can reference this property transparently. The main disadvantages of this approach are:
- You must be careful that all possible values ββare displayed in an enumeration with the corresponding identifiers. For listings that change frequently, this becomes problematic.
- Developers will still have access to the base column, unless you change the accessibility and, perhaps, can bypass the enumerations and use whatever value they like.
source share