I've gotten somewhat lost between the sheets of EF... Like the rest of the free world, I really have a need to use Enums in my POCOs. Like many I talk to, I would thoroughly enjoy mapping Enums using code only because, well I just don't like pictures all that much.
My quandary here is that I am getting conflicting information on nearly every article I pull up. It gets even harder sifting out the custom implementations or "extensions" people have published to try and work around the EF shortfall.
The EF June CTP announces support for Enums and Spatial Types but it appears that support only comes when using the designer? And also, is the June CTP part of the EF 4.1 Update 1 or still not RTM?
If there's a way to support Enums using the Fl开发者_StackOverflow社区uent API, I would be indebted to anyone who can help me out or steer me in the right direction!
Thanks, Jason
Enums are not supported by current EF version. They are supported in June 2011 CTP for both EDMX and code mapping but that CTP doesn't have production version - it is not part of EF 4.1 Update 1 or upcomming EF 4.2. Imho if we will be very lucky it will be part of .NET 4.5.
The easiest way to use enums now is using two properties: mapped int and non mapped enum property converting from mapped int:
public class Test
{
public int EnumValue { get; set; }
public EnumType Value
{
get { return (EnumType)EnumValue; }
set { EnumValue = (int)value; }
}
}
You cannot use enums in Linq to entities queries when using this approach.
Enum is not support in EF at this stage. The latest 4.2 release only has bug fixes. Seem like Enum support will be in EF 5 which will come out with .Net 4.5. Please read http://social.msdn.microsoft.com/Forums/en/adodotnetentityframework/thread/67a9247e-eccf-4b14-9da1-db630e408ae8
精彩评论