Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to map int into enum with EF

Is there anyway to map int field into enum in EFv1? Thanks! I want my entity to have enum field rather than int field.

like image 675
Roy Avatar asked Jan 15 '10 08:01

Roy


2 Answers

Create two properties. One mapped to EF, one as a wrapper

[EdmScalarProperty]
public int EnumPropInteger {get;set}
public MyEnum EnumProp
{
    get { return (MyEnum) EnumPropInteger; }
    set { EnumPropInteger = (int)value; }
}

Not a nice way because you have two public properties but a way.

like image 166
Arthur Avatar answered Nov 18 '22 21:11

Arthur


It's supported with the new release : Now supported : http://blogs.msdn.com/b/adonet/archive/2011/06/30/announcing-the-microsoft-entity-framework-june-2011-ctp.aspx

like image 41
VinnyG Avatar answered Nov 18 '22 19:11

VinnyG