AssertionFailure: “null identifier” - FluentNH + SQLServerCE

前端 未结 2 1806
盖世英雄少女心
盖世英雄少女心 2020-12-15 08:05

The code fails at

session.Save(employee);
with AssertionFailure \"null identifier\". What am I doing wrong?

using FluentNHibernate.Cf         


        
相关标签:
2条回答
  • 2020-12-15 08:54

    There's a "bug" when using NHibernate with SQL CE identity columns. There are two workarounds that I know of:

    1 - Set the connection.release_mode property to on_close in configuration:

    mySessionFactory = Fluently.Configure()
        .Database(MsSqlCeConfiguration.Standard
        .ConnectionString("Data Source=MyDB.sdf"))
        .Mappings(m => m.FluentMappings.AddFromAssemblyOf())
        .ExposeConfiguration(BuildSchema)
        .ExposeConfiguration(x => x.SetProperty("connection.release_mode", "on_close"))
        .BuildSessionFactory();
    

    2 - Perform inserts in a transaction:

        using (ISession session = DB.OpenSession())
        using (ITransaction txn = session.BeginTransaction())
        {
            session.Save(employee);
            txn.Commit();
        }
    

    I realize the question is more than a month old but I hope this answer is still of use to you.

    0 讨论(0)
  • 2020-12-15 09:02

    Is is still the true. Even first call to SELECT @@IDENTITY returns corect value, but seconds returns null

    I use

    *connection.driver_class = NHibernate.Driver.SqlServerCeDriver dialect: NHibernate.Dialect.MsSqlCeDialect*

    After adding property *connection.release_mode: on_close* to my NHIbernate configuration it works

    0 讨论(0)
提交回复
热议问题