I am using the Repo pattern, and I have set up tests to replicate my a HTTP request coming in and then causing dispose on a unit of work once a test has completed.
It ap
I faced a similar problem. I'll first tell you what causes this. When NHibernate
fetches an entity from the DB
it assigns values to it's props. There are few props that have null values in the DB
but are not of Nullable
type in the class definition. So NHibernate
assigns them a default value eg. 0
for int
, DateTime.MinValue
for datetime
etc. When you call commit on the transaction, NHibernate
rechecks the values of properties with DB
values and since props which should have had Null
values now have a default value, NHibernate
thinks that the values have been changed and causes an update.
Solution:
nullable datatypes
for your class props by post fixing them with
?
but for me this is causing other problems.Not Null
Types but this is not preferable in
most cases.Null
values
in the Db
Nhibernate
saves some default value and this stops the
calls to unnecessary updates.You may further google NHibernate ghostbuster
for more research on this problem.
NHibernate typically runs updates when it has transient or detached entities that it isn't sure about. That is, entities that it doesn't know if it has a parent for that manages it or if its not sure the entity is dirty. This is typically a symptom of a bad mapping somewhere (a missing Inverse on some parent) or you have no Version or Date column on your entities.