title: Is it possible to update/change a primary key with NHibernate?
body: <p>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. </p>
  
  <p>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. </p>
  
  <p>For example, say I have a 'Business' object with a 'BusinessCode' as it's primary key:</p>
  
  <pre><code>public class Business
  {
      public string BusinessCode { get; set; }
  
      public string Name { get; set; }
  
      ...
  }
  </code></pre>
  
  <p>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 <em>Save()</em>, <em>Update()</em>, or <em>SaveOrUpdateCopy()</em>)</p>
  
  <pre><code>Business b = session.Get&lt;Business&gt;("BusinessCode1");
  
  b.BusinessCode = "BusinessCode22";
  
  session.Update( b );
  </code></pre>
  
  <p><strong>So is something like this possible?</strong> </p>
  
  <p>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. </p>