I have a database that uses natural keys (i.e. business oriented keys). Unfortunately, because of this, the primary keys for these objects may change over time.
I am currently researching the use of NHibernate for an O/RM for this database. However, in my testing I have noticed that there is no apparent way to change the primary key of an object and save it to the database.
For example, say I have a 'Business' object with a 'BusinessCode' as it's primary key:
public class Business
{
public string BusinessCode { get; set; }
public string Name { get; set; }
...
}
If I do a Get, change the primary key, and try and save it back to the database using NHibernate, I either receive an exception or unexpected results (depending on if I use Save(), Update(), or SaveOrUpdateCopy())
Business b = session.Get<Business>("BusinessCode1");
b.BusinessCode = "BusinessCode22";
session.Update( b );
So is something like this possible?
I understand that many NHibernate folks recommend using primary keys that do not change (i.e. identities). But I have a couple DB's that use natural keys. Thanks.