David Fornas
David Fornas

Reputation: 462

How can I implemente Save/Discard functionality with NHibernate?

I have a working WPF app using MVVM pattern in which the ViewModel calls Queries that do all the save/update/get/delete stuff. I did this because it's easy to modify that queries to swap storage system, for example.

The app is working fine if the data is stored/deleted on the fly but the client wants a Save button so I have to remember (or Nhibernate) which changes are made. I don't want to have a session open long time so I don't know best way to do it. Do you know any pattern/architecture that would work?

Upvotes: 1

Views: 177

Answers (1)

Firo
Firo

Reputation: 30813

this worked for me for a simple app:

  • open session for viewmodel
  • if not use a transaction then Flushmode.Never (prevents queries from flushing)
  • use id generator which generates client side ids (hilo, guidcomb,...)
  • dont use Flush after the CRUD
  • check session.IsDirty to enable savebutton
  • if save -> flush() or commit
  • if cancel -> Dispose session or rollback

NH will then send all actions at the end on flush

Upvotes: 1

Related Questions