Enum to integer mapping causing updates on every flush

670 views
Skip to first unread message

Ian Nelson

unread,
Aug 20, 2010, 10:25:48 AM8/20/10
to fluent-n...@googlegroups.com
Hi All,

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<int>();

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 in advance

Ian

Ian Nelson
20-08-2010 14-56-58.png

Ian Nelson

unread,
Aug 20, 2010, 10:29:44 AM8/20/10
to fluent-nhibernate
20-08-2010 14-56-58.png

Nick Webb

unread,
Aug 21, 2010, 11:35:54 AM8/21/10
to fluent-n...@googlegroups.com
I believe NH uses an int to represent an enum, by default, and FNH a string.  Your FNH mapping also seems correct.  I'm wondering if there's some kind of collision going on within FNH.  What happens if you don't specify an int as the custom type?  IE: .CustomType();



--
You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group.
To post to this group, send email to fluent-n...@googlegroups.com.
To unsubscribe from this group, send email to fluent-nhibern...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en.

MaggiePlusPlus

unread,
Aug 21, 2010, 4:04:06 PM8/21/10
to Fluent NHibernate
We use both of these to map enums to ints with no issues

Map(x => x.ContactType, "ContactTypeID").CustomType<ContactType>();
Map(x => x.ContactType,
"ContactTypeID").CustomType(typeof(ContactType));

Maggie

Asbjørn Ulsberg

unread,
Oct 19, 2010, 6:59:19 PM10/19/10
to fluent-nhibernate, Ian Nelson
On Fri, 20 Aug 2010 16:29:44 +0200, Ian Nelson <ianfn...@gmail.com>
wrote:

> I understand that this should be possible using a fluent mapping like:
>
> Map(x => x.DayOfWeek).CustomType<int>();

Try

Map(x => x.DayOfWeek).CustomType<DayOfWeek>();

instead.

--
Asbjørn Ulsberg -=|=- asb...@ulsberg.no
«He's a loathsome offensive brute, yet I can't look away»

Reply all
Reply to author
Forward
0 new messages