When I update (with a flush) one record in a list of records retrieved from the database nHibernate is versioning all of the records that were in the original list.
Retrieving a list of records from the database:
using(UnitOfWork.Start())
{
queuedJobs = aJobServiceManager.GetAllJobs().Where(aJob => aJob.Status == PricingStatus.QUEUED).ToList();
}
/* Do some work on the record*/
using(UnitOfWork.Start())
{
//aJob is a record from queuedJobs.
aJobServiceManager.Save(aJob);
//When Flush is called I'm expecting only aJob to be updated in the database.
//aJob is correctly updated BUT
//All the other records in queuedJobs are also updated (their version field is incremented).
UnitOfWork.Current.Flush();
}
Why is nHibernate updating all the records when they haven't changed and how do you stop this behavior?
This is most likely the problem you're running into: http://nhibernate.info/blog/2008/10/20/how-test-your-mappings-the-ghostbuster.html
It would help to see your mapping file for job. If you're doing something like
<property name="Status" type="int" />
Where Status
is actually StatusEnum
you'll end up with ghosting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With