Mohit Arora
Mohit Arora

Reputation: 347

Mapping Enum Error FluentNhibernate

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.

Upvotes: 0

Views: 1110

Answers (1)

Radim K&#246;hler
Radim K&#246;hler

Reputation: 123901

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?

Upvotes: 1

Related Questions