簡體   English   中英

映射枚舉錯誤FluentNhibernate

[英]Mapping Enum Error FluentNhibernate

我想將一個enum映射到mysql數據庫。

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

這是我的mapping類。

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

這顯示了一個錯誤。 試過了

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

兩者都顯示錯誤。

請幫忙。

我會說,這里提到的解決方案沒有什么不同:

用流利的hibernate映射枚舉

因此,如果包含整數列,我們可以像這樣映射它:

// 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);

如果您有字符串列(值O,PP,...),則您的嘗試應該起作用:

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

如此處所述: 如何在流利的nhibernate中將枚舉映射為字符串?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM