Tuesday, August 18, 2015

NHibernate: Collection is always dirty

A collection that loaded from database is always dirty, that because there's a problem in mapping file. 

For example: In class A has a property named Kind with data type is an enum short. In the mapping file, this property should be mapped without specify a data type such as
        <property name="Kind" not-null="true"/>


If in the mapping file you specify a data type
        <property name="Kind" type="short" not-null="true" />


What will happen?

Problem:
When NHibernate compares your collection, this property will be conflict between short and your enum, eg: in database column Kind has value is 0, and the enum mapped to this Kind is N/A=0. At comparison time, NHibernate will treat it like a dirty data when checking it and will post an update action queue for your object even that object didn't get any modification.


No comments:

Post a Comment