0

I want to Map an enum to mysql Database.

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

This is my mapping Class.

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.

Nerdroid
  • 13,398
  • 5
  • 58
  • 69
Mohit Arora
  • 337
  • 5
  • 19

1 Answers1

1

I would say, there is nothing different then solution mentioned here:

Mapping enum with fluent nhibernate

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:

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

As discussed here: How do you map an enum as string in fluent nhibernate?

Community
  • 1
  • 1
Radim Köhler
  • 122,561
  • 47
  • 239
  • 335