I\'m doing a fairly complex NHibernate transaction in a financial system, creating a payment, recording the ledger entries, checking to see if the payment is the total amoun
In my case it was a missing Identity Specification on the SQL-Server.
Simple object:
public class Employee
{
public virtual int ID { get; set; }
}
Mapping:
public class EmployeeMap : ClassMapping
{
public EmployeeMap()
{
Id(x => x.ID, map => { map.Generator(Generators.Identity); map.UnsavedValue(0); });
}
}
SQL:
Here is the ID column with the primary key constraint.
And here you can see the missing Identity Specification, which is causing the problem.
To solve the problem, you have to specify the ID column as IDENTITY
i.e.
CREATE TABLE EMPLOYEE
(
ID int NOT NULL IDENTITY(0, 1)
);