How can I update a row and insert a new one automatically in NHibernate with one call to Save?
        Posted  
        
            by snicker
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by snicker
        
        
        
        Published on 2010-03-10T23:56:56Z
        Indexed on 
            2010/03/15
            20:19 UTC
        
        
        Read the original article
        Hit count: 372
        
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.
© Stack Overflow or respective owner