可以在实体框架中使用非整数枚举吗?

时间:2017-05-16 15:52:57

标签: entity-framework

我正在使用Entity Framework 6.1(.NET 4.5)并注意到一些奇怪的事情:

实体类中的简单枚举属性在如下定义时工作正常:

public enum TestEnum
{
    ValueOne,
    ValueTwo
}

//then used in an entity class like this:
public class MyClass
{
    public TestEnum MyTestEnum { get; set; }
}

...但不是,当它被定义为非int32类型时,如下所示:

public enum TestEnum : ushort
...

使用前者,Entity Framework会自动检测并将属性映射到int列。对于后者,EF甚至没有检测到实体类中存在该属性。如果我试图强迫它,

...Property(x => x.MyTestEnum).IsRequired();

我收到以下迁移错误:

The property 'MyTestEnum' is not a declared property on type 'MyClass'. Verify that the property has not been explicitly excluded from the model by using the Ignore method or NotMappedAttribute data annotation. Make sure that it is a valid primitive property.

EF中不支持ushort枚举吗?

0 个答案:

没有答案