views:

2086

answers:

2

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

Remarks: I'm using EF 3 againts Firebird.

+3  A: 

This is one of those irritating things about EF. Will not be supporting it yet!

Or you can do something like:

public MyEnum MyEnumProperty  
{  
  get { return (MyEnum) InnerEnumProperty; }  
  set { InnerEnumProperty = (int) value; }  
}

But it makes me feel dirty.

Geoff
I already knew this workaround, and it really looks dirt.But...
Rafael Romão
its kinda dirty, but there is another problem, if you use this field inside a query, EF will complain. For that problem I created this wrapper: http://landman-code.blogspot.com/2010/08/adding-support-for-enum-properties-on.html which from the outside of your entity allows you to remain clean of EF details..
Davy Landman
+4  A: 

There is a somewhat better way to do it in EF 4. Unfortunately, it won't work in EF 1.

Here's another approach.

Craig Stuntz
the other approach works for EF1 and EF4 btw.
Davy Landman