views:

371

answers:

1

I start build a system with distributed architecture by all applications will communication by REST service to expose some data(DTO) or invoke some updates. I would like to know how to use NHibernate to help with manage domain object because they are in different applications. How NHibernate identify which objects are new for inserting and old for updating?

+1  A: 

If you want to learn quickly about how NHibernate works, go have a look at the excellent video series by Stephan Bohlen called Summer of NHibernate.

He shows everything from the very simple NHibernate setup, all the way to using NHibernate in complex environments.

NHibernate keeps track of the objects it queried in a "session", and that's how it knows whether or not objects have been changed. Additionally, you will most likely define a primary key on your objects and define a value that signals to NHibernate that this is a new object that hasn't ever been saved to the database (e.g. having a "0" in an ID field might signal --> this is a new object).

All this is shown and explained in great detail in the Summer of NHibernate series - worth watching!

Marc

marc_s