如何映射查找表来枚举?

2023-09-03 16:04:09 作者:修罗王 ° roI ■

假设我有以下2 SQL表:

Suppose i have the following 2 SQL tables:

Column        DataType
---------------------------
Title         NVARCHAR(20)
Body          NVARCHAR(MAX)
FooTypeId     TINYINT

FooType

Column        DataType
--------------------------
FooTypeId     TINYINT
Name          NVARCHAR(10)

现在,使用实体框架4.0自定义数据环境和POCO实现。IM

Now, im using Entity Framework 4.0 with a custom data context and POCO implementation.

我如何映射这对设计师,我的POCO的?

How do i map this on the designer, and my POCO's?

我要创建一个POCO属性(类型字节的我承担)被称为FooTypeId,然后我暴露我的枚举类型的另一个属性?

Do i have to create a POCO property (of type byte i assume) called "FooTypeId", then i expose ANOTHER property of my enum type?

IE浏览器。

public class Foo
{
    public byte FooTypeId { get; set; } // for ORM - do i need this??
    public FooType FooType // for most querying operations
    {
         get
         {
            return (FooType)this.FooTypeId;
         }
         set
         {
            this.FooTypeId = (int)value;
         }
    }
}

public enum FooType
{
    Blah = 1,
    Foo = 2,
    Bar = 3
}

在那一刻,我甚至不具备 FooType 表我的设计师,因为我想我可以在实际FooTypeId试图恩preSS这是一个枚举富财产。 或者我应该创建的映射器导航属性,然后定义,在我的POCO?

At the moment, i do not even have the FooType table on my designer, as i figured i can try and "express" this as an enumeration from the actual FooTypeId on the Foo property. Or am i supposed to create a "Navigational Property" on the mapper, then define that in my POCO?

我从几年前(EF1)说:枚举不支持EF读线程,这仍与EF4的情况?如果是,是什么即时做吧?

I've read threads from a few years back (EF1) saying "Enums are not supported in EF", is this still the case with EF4? If it is, is what im doing right?

样的我在这里失去了一些指导,将大大AP preciated!

I'm kind of lost here, some guidance would be greatly appreciated!

推荐答案

目前,EF4不支持枚举本身。

Currently, EF4 doesn't support enums natively.

我已经看到AlexJ一个伟大的解决方法,工作pretty的好(它的pretty的code重型虽然),http://blogs.msdn.com/b/alexj/archive/2009/06/05/tip-23-how-to-fake-enums-in-ef-4.aspx

I've seen a great workaround by AlexJ that works pretty well (it's pretty code heavy though), http://blogs.msdn.com/b/alexj/archive/2009/06/05/tip-23-how-to-fake-enums-in-ef-4.aspx

我还听说,这个原生支持ENUM即将在EF4的下一个版本,但谁知道什么时候会被释放。

I've also heard that this native enum support is coming in the next version of EF4, but who knows exactly when that will be released.

相关推荐