How can I update a row and insert a new one automatically in NHibernate with one call to Save?
- by snicker
Let's say I have a Type II SCD database, that is basically append only. I am using NHibernate to persist objects to my database. I have an object like so:
Pony
|- int Id
|- Guid EntityId
|- string PonyName
|- string PonyColor
|- int RevisionValidFrom
|- int RevisionValidTo
Here's a typical scenario:
Pony myLittlePony = myStable.GetLatestPonyByGuid("0f1ac08a-3328-43db-b278-77c272e4fea3");
myLittlePony.PonyColor = "Fish";
myNHSession.Save(myLittlePony);
I want to be able to call Session.Save(myLittlePony) and have NHibernate UPDATE the old entity's RevisionValidTo to whatever I specify and then INSERT the modified Pony as a new row with a new Id, basically as if it were a brand new object being persisted to the DB.