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.