Using NHibernate mapping by code: Cannot insert explicit value for identity column in table 'DietUser' when IDENTITY_INSERT is set to OFF
问题 Took me a while to find an answer for this so thought I'd share the love. When using NHibernate's new mapping by code with SQL Server I'm unable to save an entity. When saving an entity a System.Data.SqlClient.SqlException is thrown with the following message (minus the table name): "Cannot insert explicit value for identity column in table 'DietUser' when IDENTITY_INSERT is set to OFF." My table uses an identity ID and the entity & mappings look like this: public class User { public virtual