Enum to integer mapping causing updates on every flush
I am trying to map an enum property (instance of System.DayOfWeek) in my model to map to an integer database field.
Other enum properties in the model should be mapped to strings, so I don't wish to define a convention.
I understand that this should be possible using a fluent mapping like:
Map(x => x.DayOfWeek).CustomType();
and indeed, at first glance this appears to be working.
However, I noticed that instances of entities with properties mapped in this way are being updated every time the session was flushed, even though no amendments have been made to them.
To find out what is causing this flush, I set up an IPreUpdateEventListener, and inspected the OldState and State of the entity.
See the attached image. In the OldState, the relevant object is an int, whereas in State it is a DayOfWeek.
If I use an HBM XML mapping with no type attribute specified, this issue doesn't arise.
So...
Is this a bug or shortcoming in the GenericEnumMapper?
Is there any way of telling the FNH mapping not to specify any type attribute on the generated HBM?
If not, can I specify the default type that NH uses for enums (and what is that)?
Thanks
20-08-2010_14-56-58.png 29.5 KB
2 Posted by Ian Nelson on 20 Aug, 2010 03:15 PM
Sorry, lost some of the markup on my mapping. Should have said
Map(x => x.DayOfWeek).CustomType<int>();
3 Posted by Sreenivas Kothapalli on 23 Aug, 2010 12:32 PM
We don't use FluentNHIbernate. We use XML mapping.
But we too faced the same problem when the type of the enum field is specified explicitly as 'int' in the mapping file, updates did take place on autoflush. But when we removed specification of the type, the UPDATEs disappeared.
Hope that helps.