Hi,
Is there anyway to map int field into enum in EFv1? Thanks! I want my entity to have enum field rather than int field.
Hi,
Is there anyway to map int field into enum in EFv1? Thanks! I want my entity to have enum field rather than int field.
You can simply cast the int to the Enum like this:
public enum TestEnum
{
Zero = 0,
One,
Two
}
TestEnum target = (TestEnum)1;
Target should then contain TestEnum.One;
Edit: My bad, did not interpret properly at first. You want the map to handle the cast for you, right? Don't know that right now, would have to experiment a bit.
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.