Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enums EF 5.0 - Database First

How can I make it so that my context objects uses the Enum feature in Entity Framework 5.0 if I am using Database First.

like image 356
LazyTarget Avatar asked Jul 21 '12 18:07

LazyTarget


People also ask

Should enums be stored in database?

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.

How do I store multiple enums in a database?

You can use the '|' (bitwise OR ) operator to mask multiple roles together in a single 64-bit integer, which you can store in the database in an integer field (a bigint ). RoleEnum userRoles = RoleEnum. User | RoleEnum.

How are enums numbered?

Numeric enums are number-based enums i.e. they store string values as numbers. Enums are always assigned numeric values when they are stored. The first value always takes the numeric value of 0, while the other values in the enum are incremented by 1.


1 Answers

Go to the model browser and create a new enum type, then go to whatever column you wish to use it on and change its type to the enum that you just created.

like image 192
Adam Robinson Avatar answered Sep 23 '22 12:09

Adam Robinson