无法编译映射文件nhibernate

时间:2018-05-07 19:42:07

标签: c# asp.net-mvc nhibernate

大家好我是nhibernate的新手,请你帮我检查一下是否有问题?即时通讯使用hbibernate + webapp mvc visual studio 2017:

    private void BuildConfiguration()
    {
        //error here
        Configuration.Configure(@"~\Models\hibernate.cfg.xml");

        //already tried next command with same error
        //Configuration.Configure(@"~\Models\hibernate.cfg.xml");

        Configuration.AddAssembly(GetType().Assembly);
        Configuration.AddFile(@"~\Mappings\Users.hbm.xml");
}

的hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">
  NHibernate.Connection.DriverConnectionProvider
</property>
<property name="connection.driver_class">
  NHibernate.Driver.SqlClientDriver
</property>
<property name="connection.connection_string">
  Server=(localdb)\SQLEXPRESS;database=dbtest;Integrated User ID=sa;Password=sa123;
</property>
<property name="dialect">
  NHibernate.Dialect.MsSql2012Dialect
</property>

1 个答案:

答案 0 :(得分:0)

这个问题与asp .net core 2 httpcontext.current / nhibernate兼容性问题有关

中的

configuration.Configure();
configuration.AddFile();

我没有使用httpcontex.current,我已经尝试了Microsoft.AspNetCore.Session和IHttpContextAccessor,但是当前仍为null

所以我决定转移到该项目的实体框架。