Can we update Id fields in NHibernate like the following?
MyClass myObj = MyClass.Retrieve(1);
myObj.Id = 999;
myObj.Name = "name name";
myObj.Value = 1000;
MyClass.Update(myObj);
Can we update Id fields in NHibernate like the following?
MyClass myObj = MyClass.Retrieve(1);
myObj.Id = 999;
myObj.Name = "name name";
myObj.Value = 1000;
MyClass.Update(myObj);
Something like this will work:
ISession.Delete(yourClass);
yourClass.Id = somethingelse;
ISession.Save(yourClass);
Why do you want to change an Identifier? It sounds like a very bad thing to do.
You should never change the identifier (primary key) on an existing object. With NHibernate, you should only assign the identifier on new objects if you've mapped the generator as "assigned". If you're intent is to clone an existing object, then retrieve the object and create the clone as a new instance so that a new identifier is assigned.
You can close the session, execute raw sql to change the primary key, and then open a new session. that is the only thing that works as nhibername relies on primary key identity. you will never ever be able to make nhibernate do it.