NHibernate - Only persist changes when a save/update call is made -


nhibernate auto saves changes made object regardless of whether make session.save/update call or not when committing transaction. eg.

session.begintransaction();  user user = repos.getuser("tony");  user.age = 34  transaction.commit(); 

age updated. can annoying when want object db , make changes without changes being saved. can session.evict object, lose ability load proxies.

is there way nhibernate persist changes if save/update call made?

update:

thanks responses, no 1 told me how (and may not possible) going leave unanswered.

you should wrap db calls in transaction , commit transaction close it.

i doing because there complex sorting of results isn't possible via sql/nhibernate. unfortunately nhibernate assumes want save new order db.

my workaround add property transaction attribute [transaction(onlyread = true)] causes use flushmode.never

i think future work make sure make changes want persist. pity there isn't option save when explicitly call it.

this how nhibernate sessions designed work.

if you'd rather manually, use istatelesssession instead. you'll lose caching, lazy loading, etc.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -