tags:

views:

41

answers:

2

Given I have a scenario where two users are editing different address object at the same time.*

User 1 edits address.streetname only and saves and User 2 edits address.town and saves.

Is there anyway I can configure nhibernate so that only the changed fields are updated and thus the changes are merged?

I have tied dynamic-update, but his doesnt do the trick, its more an optimization technique.

dynamic-update="true"

I also experimented with version but this does not seem to have the desired effect.

<version  name="Version"  type="int" column="Version"/>
  • I appreciate this is a weird scenario, but it is the requirement I was given.
+2  A: 

Strictly speaking, this is not "merging" per se: there's always a possibility of losing data (and it's very serious, I should add). dynamic-update should do the trick, but if you're detaching an object from an ISession it won't work and you'll need to set select-before-update to true as well so that NHibernate will re-read a particular record from the DB.

Anton Gogolev
+1  A: 

I suggest you challenge that requirement.

In the example you gave, it might be ok, but in many cases it will be functionally inconsistent to merge updates mechanically, without an explicit functional choice.

Even in the example given, suppose you add validation, checking that a street exists in the town : your validation could let pass the two updates, and your data would become corrupt!!

KLE