我该如何映射使用实体框架4.1流利的API枚举?我该、流利、实体、框架

2023-09-06 13:12:26 作者:你要的幸福、只能我给

我已经得到了一定程度的EF的片之间失去了...喜欢自由世界的其他地方,我真的需要使用枚举在我的波苏斯。像许多我倾诉,我会用code只是因为,好吧我只是不喜欢的图片所有的东西彻底享受映射枚举。

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.

在这里我困惑的是,我得到相互矛盾的几乎每一篇文章我拉起来的信息。它会变得更难筛选出来的自定义实现或扩展的人发表试着和周围的EF不足的工作。

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.

借助 EF六月CTP 宣布为枚举和空间类型,但支持看来支持使用设计时只配备?而且,是EF 4.1 Update 1或6月份CTP部分还没有RTM?

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?

如果有一种方法来支持使用流利的API枚举,我会很感激的人谁可以帮我出或转向我的方向是正确的!

If there's a way to support Enums using the Fluent API, I would be indebted to anyone who can help me out or steer me in the right direction!

谢谢,杰森

推荐答案

枚举不支持当前EF版本。他们是在2011年6月的CTP支持两个EDMX和code映射但CTP没有量产版 - 它不是EF 4.1 Update 1或upcomming EF 4.2的一部分。恕我直言,如果我们将是非常幸运这将是.NET 4.5的一部分。

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.

现在使用枚举最简单的方法是使用两个属性:映射int和非映射枚举财产映射INT转换:

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; }
    }
}

您不能在LINQ的使用这种方法时,使用枚举实体查询。

You cannot use enums in Linq to entities queries when using this approach.