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.

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.