I have an object which is already exists in the database and I want to modify it’s ID,
Nhibernate is considering it as a new object and save it instead of update.
I have many silly solutions in mind but I want the efficient one.
I have an object which is already exists in the database and I want
Share
Its a little difficult to answer, because it’s pretty unclear what you want to do… What’s the context of this question? Why do you even want to change an ID? Maybe its something like a customer ID?
Well, I’d say the best solution is to separate your business logic from your technical logic. It is often advised to have a meaningless primary key. Of course there are reasons against this but is you already know your ID might change, I’d say add an ID that does not change.
Anyway, if you cannot add a meaningless ID that does not change, just first delete the entity with the old ID and then add the new one with the new ID.