Inserting Parent Child records using NHibernate IDENTITY INSERT OFF

One of the errors I received when I was trying to get the parent child insert to work with NHibernate was:

  • Ein expliziter Wert für die Identitätsspalte kann nicht in der ‘CHILD’-Tabelle eingefügt werden, wenn IDENTITY_INSERT auf OFF festgelegt ist
  • Cannot insert explicit value for identity column in table ‘IdentityTable’ when IDENTITY_INSERT is set to OFF.

My initial action was to access SQL Server and set the value to ON. Wrong!

However, after some analysis I realized that I had forgotten to set my generator in the child mapping file.:

<generator class="***" />

Once I set that up, everything was working again.