Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to work with Enums in Entity Framework?

What is the best way to work with Enums in Entity Framework?

Remarks: I'm using EF 3 and Firebird.

like image 766
Rafael Romão Avatar asked Oct 06 '09 15:10

Rafael Romão


People also ask

How do you use enums?

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”).

How do enums work in C#?

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.

Can two enums have the same value?

1. Two enum names can have same value. For example, in the following C program both 'Failed' and 'Freezed' have same value 0.


1 Answers

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.

like image 122
Craig Stuntz Avatar answered Oct 24 '22 22:10

Craig Stuntz