NPersist has a feature which allows you to do this essentially:
ISession sessionWrapper = sessionFactory.OpenSession(instanceOfSessionActuallyConnectedToDatabase);
/* This statement retrieves a Customer from the DB using the instanceOfSessionActuallyConnectedToDatabase, then returns a _clone_ of the retrieved Customer business object */
Customer c = (Customer) sessionWrapper.Get(32,typeof(Customer));
c.Name ="Jim";
/* This does NOT save the changes to the database, instead it saves the changes to the instanceOfSessionActuallyConnectedToDatabase instance of the Customer */
sessionWrapper.Save();
What's the point you say?
I can make changes to a business object and catch exceptions thrown from them in the presentation layer and display the appropriate info to the user. This means I don't have to repeat my business rules in the presentation layer. When the user click's Save, my changes are written back to the NHibernate Customer proxy (but not to the database). If the user click's Cancel I just discard the wrapper session. Is there anything like this in the works for NHibernate. It seems like it would be (relatively) easy to do by just implementing the ISessionImplementor and wrapping a Session?
This is where all the NHibernate heavyweights hang out (you guys rule - I'm not worthy!) so if I can't get an answer here I'll assume that there is none.
|