dragonfly
dragonfly

Reputation: 17773

Force entity refresh after update

I'm using an entity that has properties computed by view. In my sample scenario:

  1. I'm getting the entity from database & I'm changing a few properties of this entity
  2. I'm saving this entity session.Update(entity)
  3. 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:

  1. I'm getting the entity from database & I'm changing a few properties of this entity
  2. I'm saving this entity session.Update(entity) & refreshing in one database trip.

Is it possible?

Upvotes: 1

Views: 1091

Answers (1)

Jamie Ide
Jamie Ide

Reputation: 49251

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)

Upvotes: 4

Related Questions