NHibernate 询问 hibernate.cfg.xml 即使 web.config 配置

NHibernate asks hibernate.cfg.xml even if web.config configured

这是 ASP.NET MVC 5 示例应用程序。 尝试学习 MVC 的模块 NHibernate。

如果我没理解错的话。 hibernate.cfg.xml 如果设置在 web.config 中编码为配置部分,则不需要文件。

是不是xmlns版本有误?或者你看到拼写错误的东西吗? 那么为什么 NHibernate 会询问 hibernate.cfg.xml,即使 web.config 已配置? (感谢)

<configSections>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler,NHibernate" />
...

<hibernate-configuration xmlns="urn:nhibernate-configuration-version-2.2">
    <session-factory>
  <property name="dialect">NHibernate.Dialect.MySQLDialect</property>
  <property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
  <property name="connection.connection_string_name">LocalMySqlServer</property>
</session-factory>
</hibernate-configuration>

出现此错误:

Could not find file '...\Visual Studio 2013\Projects\bin\Debug\hibernate.cfg.xml'.

和 DB Class 静态成员(在 global.asax.cs Application_Start 方法中使用过一次)是:

public static void Configure()
    {

        var config = new Configuration();
        config.Configure();


        var mapper1 = new ModelMapper();
        mapper.AddMapping<UserMap>();
        config.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
        _sessionFactory = config.BuildSessionFactory();

// _session factory is a class member defined as 
// private static ISessionFactory _sessionFactory;
    }

已安装 NHibernate 4.0.3.4000 [使用 nuget]

找到答案了。似乎在新的 nhibernate 版本中更改了方案密钥

已更改

<hibernate-configuration xmlns="urn:nhibernate-configuration-version-2.2">

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">

修复了问题。我确定,因为我重新测试了第一个方案。和BOM!同样的错误抛出。所以 xmlns 字符串被更新。

我是怎么找到它的。 在菜单 > 方案中打开 web.config>xml [添加了 nhibernate xsd 文件,您可以在 project\packages 中找到这些文件 比自动完成确实在 web.config 中工作并向我显示了正确的模式字符串。