2

I have something similar to this

var productList = order.Products.TolIst();

And I loop through the productList and update each product using

session.SaveOrUpdate(product);

But the problem is, the previous state of the product in OnFlushDirty function is null (Which make sense).

Is there anyway to manage/ copy/ inject the previous state?

Thanks

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Hello World
  • 328
  • 4
  • 12

1 Answers1

2

This could be related to detached objects updating. Try to read this very similar story: http://jamesfitzsimons.com/?p=152

Summary of the issue:

... On investigation we realised that the previousState parameter passed into the onFlushDirty method of our interceptor was null. ...

The solution:

The solution was to use the merge() method (new in NHibernate 2.0). Merge() checks the first level cache to see if an object with the given identifier has previously been loaded. If so it loads that object out of the first level cache and updates it’s properties using the detached object. This means that the session is now able to track the changes made to the object so that when the flush occurs the previousState is no longer null.

Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
  • Thanks for the answer. I found this one also usefull http://stackoverflow.com/questions/170962/nhibernate-difference-between-session-merge-and-session-saveorupdate – Hello World Jan 31 '13 at 13:04
  • Yeah, stackoverflow and google search should be always the first option ;) – Radim Köhler Jan 31 '13 at 13:21