What is the best way to work with Enums in Entity Framework?
Remarks: I'm using EF 3 and Firebird.
You should always use enums when a variable (especially a method parameter) can only take one out of a small set of possible values. Examples would be things like type constants (contract status: “permanent”, “temp”, “apprentice”), or flags (“execute now”, “defer execution”).
In the C# language, enum (also called enumeration) is a user-defined value type used to represent a list of named integer constants. It is created using the enum keyword inside a class, structure, or namespace. It improves a program's readability, maintainability and reduces complexity.
1. Two enum names can have same value. For example, in the following C program both 'Failed' and 'Freezed' have same value 0.
There is a somewhat better way to do it in EF 4. Unfortunately, it won't work in EF 1.
Here's another approach.
Update: Real enum support was added in the June 2011 EF CTP.
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