NHibernate: Error dehydrating property - What the heck is this?

前端 未结 6 2057
谎友^
谎友^ 2021-01-17 10:21

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

6条回答
  •  北恋
    北恋 (楼主)
    2021-01-17 10:23

    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)
    );
    

提交回复
热议问题