I’m using an entity that has properties computed by view. In my sample scenario:
- I’m getting the entity from database & I’m changing a few properties of this entity
- I’m saving this entity session.Update(entity)
- I’m calling session.Refresh(entity) , as some columns computed by the view can change as a result of my changes.
So NHibernate if forced to have three trips to database.
What I’m trying to achieve is to have only two trips:
- I’m getting the entity from database & I’m changing a few properties of this entity
- I’m saving this entity session.Update(entity) & refreshing in one database trip.
Is it possible?
No, it’s not possible. You have to issue three SQL commands: select, update, select. NHibernate does support batching but it batches together inserts or updates, not mixed commands.
Aditionally, NHibernate supports Generated Properties, so you don’t have to update those columns by hand (it still requires a roundtrip, but it’s transparent)