So...What you are looking for is a way to maintain the session open and the transaction alive for the whole winForm live ?
2009/2/10 Dcam <[email protected]> > > I have a WinApp with a Form in which I'd like to let the user edit a > list of Entities in a DataGridView; meaning changing existing, adding > new ones and deleting newly added or existing entities. > But the user should be able to discard all "his work" or save it. > Lates version of NHibernate 2 by the way. > > Based on secion 10.4.1 "Long session with automatic versioning" in the > manual(http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/ > html_single/#transactions-optimistic), I do the following when opening > the Form: > - open a session with ISessionFactory.OpenSession() and store it in a > class property > - load all data with Session.Load(...) > - disconnect the session with Session.Disconnect() > - bind the list of entities to the a BindingSource bound to my > DataGridView > > Editing the entities in the list is no problem. But unfortunately I > can't find a way to add/attach new entity to the session without > getting them immediately writen to the database. I just want a new > entity to add/attache to the session, so I can let NHibernate do the > required INSERT und UPDATE queries when I flush/commit the changes to > the database on button_OK. > Session.Merge and Session.Save throw an error saying that the session > is not connected. And if I do so (what I actually don't want at this > stage) then the new records are directly written to the database. > Setting Session.FlushMode to FlushMode.Commit did not work. > > Any ideas how to do that? > > Thank in advance > Daniel > > > > > > -- Fabio Maulo --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
