Nhibernate Dynamic Insert terminates with some null component properties

I have a database that does not accept null values ​​and has a default value for each field. Using free nHibernate, I get an error in Insert if I have a component that has some, but not all, populated properties. I'm just wondering how to get the DynamicInsert flag to the component level. It may be too late, but I'll just leave it here and see where it goes.

display:

 public ClientMap()
    {
        Table("Clients");
        DynamicInsert();
        DynamicUpdate();
        CompositeId()
            .KeyProperty(x => x.Accountnumber, "acct_no")
            .KeyProperty(x => x.Transferaccount, "tr_acct_no");

        Component(c => c.Address,
            m =>{
                m.Map(x => x.Streetaddress, "coaddress").Not.Nullable().Default("");
                m.Map(x => x.City, "cocity").Not.Nullable().Default("");
                m.Map(x => x.Postalcode, "costate").Not.Nullable().Default("");
                m.Map(x => x.State, "cozip").Not.Nullable().Default(""); });
    }

Test:

Client nw = new Client{ Address = new Address{Streetaddress = "my address"},Accountnumber = "6543219",Transferaccount = "1"};
    IRepository repo2 = new Repository(session);
    repo2.Save(nw);

Error:

failed to insert: [BusinessObjects.Client # BusinessObjects.Client] [SQL: INSERT INTO Clients (coaddress, cocity, cozip, costate, acct_no, tr_acct_no) VALUES (?,?,?,?,?,?)]

+3
4

, , "NotNullable" "Default", , / NHibernate , NHibernate .

, , , .

+3

. :

CREATE TABLE MyTable
(
...
    InsertDate datetime not null default getdate()
...
)

:

public DateTime? InsertDate{get;set;}

, :

Map(x => x.InsertDate).Column("InsertDate").Not.Nullable().Default("getdate()");

:

Map(x => x.InsertDate).Column("InsertDate").Generated.Insert();

, null

+1

NHibernate - - Fluent.

, , , ?

0

NHibernate ...:-) , .

0

Source: https://habr.com/ru/post/1726427/


All Articles