简体   繁体   English

映射枚举错误FluentNhibernate

[英]Mapping Enum Error FluentNhibernate

I want to Map an enum to mysql Database. 我想将一个enum映射到mysql数据库。

class CommisionWorking
{ 
    public enum Color{ O, PP, FP };
}

This is my mapping Class. 这是我的mapping类。

class CommisionWorkingMap : ClassMap<CommisionWorking>
{
    public CommisionWorkingMap()
    {
      Map(x => x.Color).CustomType<typeof(Color));
    }

This shows an error. 这显示了一个错误。 Tried 试过了

Map(x=>x.Color).CustomType<GenericEnumMapper<Color>>
Map(x => x.Color).CustomType();

Both Show Error. 两者都显示错误。

Please Help. 请帮忙。

I would say, there is nothing different then solution mentioned here: 我会说,这里提到的解决方案没有什么不同:

Mapping enum with fluent nhibernate 用流利的hibernate映射枚举

So, if the table contains integer column, we can map it like this: 因此,如果包含整数列,我们可以像这样映射它:

// instead of any of these
// Map(x => x.Color).CustomType<typeof(Color));
// Map(x => x.Color).CustomType<GenericEnumMapper<Color>>
// Map(x => x.Color).CustomType();
// this will map color to integer column with values 0 == O, 1 == PP...
Map(o => o.Color);

In case that you have string column (with values O, PP, ...) this your attempt should work: 如果您有字符串列(值O,PP,...),则您的尝试应该起作用:

Map(x => x.Color).CustomType<GenericEnumMapper<Color>>

As discussed here: How do you map an enum as string in fluent nhibernate? 如此处所述: 如何在流利的nhibernate中将枚举映射为字符串?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM