I can find a bunch of tutorials on how to implement enum support for model first and code first like these:
http://msdn.microsoft.com/en-us/data/jj248772.aspx
http://msdn.microsoft.com/en-us/data/hh859576.aspx
Can anyone explain to me or provide me with some instructions on how to properly implement enum support for database first applications. I'd imagine I'd have to start in the edmx designer and right click one of my columns in the tables and convert to enum? Thanks for any advice. I'm using .NET 4.5 and Enity Framework 5.0
By keeping the enum in your database, and adding a foreign key on the table that contains an enum value you ensure that no code ever enters incorrect values for that column. This helps your data integrity and is the most obvious reason IMO you should have tables for enums.
In Entity Framework, this feature will allow you to define a property on a domain class that is an enum type and map it to a database column of an integer type. Entity Framework will then convert the database value to and from the relevant enum as it queries and saves data.
The enum can be of any numeric data type such as byte, sbyte, short, ushort, int, uint, long, or ulong. However, an enum cannot be a string type.
Enums can be extended in order to add more values to the enumeration list in which case the Extensible property must be set to true . The syntax for an enum extension, which extends the Loyalty enum with the value Diamond, is shown below.
What I wound up doing is changing the column type to int in the database then I went into the edmx and updated model from database, then I went and added a enum type and then changed the column type in the edmx designer to be of type of that enum. Reupdated the poco's and everything Works good!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With