1

I am new to nhibernate. I am developing a small c# application, using the repository pattern. In my repository I've implemented a simple hook to detect when the entity is being saved. I call the entity's event handler to perform whatever operation the entity might need.

My problem is, that I also use the SaveOrUpdate method. Since I merely need to call the event handler on just save operations, I cannot differentiate between the save or the update in the SaveOrUpdate call.

So, in short, Is there any simple way to figure what operations will be performed - will it be a save, or an update?

vondip
  • 13,809
  • 27
  • 100
  • 156

1 Answers1

6

nHibernate will call a Save method if the ID of the entity is not set, otherwise will call Update method.

Look here:

SaveOrUpdate Vs Update and Save in NHibernate

"SaveOrUpdate() looks at the identifier and decides what is necessary in the above."

Community
  • 1
  • 1
danyolgiax
  • 12,798
  • 10
  • 65
  • 116
  • I see, well if there any way for me to detect cascading saves and run an action once they are complete? – vondip Jun 13 '11 at 02:58
  • 1
    I think you can try looking for Interceptor class. Interceptor allows you to control base NHibernate method overriding OnSave, OnFlushDirty and so on. http://elegantcode.com/2008/05/15/implementing-nhibernate-interceptors/ http://knol.google.com/k/fabio-maulo/nhibernate-chapter-11-interceptors-and/1nr4enxv3dpeq/14# – danyolgiax Jun 13 '11 at 07:02