c# - 配置持久层时出现异常

标签 c# .net nhibernate exception

我正在 Nhibernate 中使用 asp.net 中的 MySql 做一个项目。在执行代码时,我收到了类似的错误

An exception occurred during configuration of persistence layer

在下面一行

ISessionFactory factory = new NHibernate.Cfg.Configuration().Configure).BuildSessionFactory();

所以让我帮助解决错误。

这是我的配置文件

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <!-- an ISessionFactory instance -->
  <session-factory>
    <!-- properties -->
    <property name="connection.provider">
      NHibernate.Connection.DriverConnectionProvider
    </property>
    <property name="connection.driver_class"> 
      NHibernate.Driver.MySqlDataDriver
    </property>
    <property name="connection.connection_string">
      Server=localhost;Database=hrms;User ID=test;Password=test;
    </property>
    <property name="dialect">NHibernate.Dialect.MySQL5Dialect</property>
    <property name="show_mysql">true</property>
    <!-- mapping files -->
    <mapping resource="WebApp1.Job.hbm.xml" assembly="WebApp1" />
  </session-factory>
</hibernate-configuration>

最佳答案

也许配置不完整?尝试手动配置初始化,如下所示:

NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
cfg.SetProperty("dialect", "NHibernate.Dialect.MySQLDialect");
cfg.SetProperty("connection.driver_class", "NHibernate.Driver.MySqlDataDriver");
cfg.SetProperty("connection.connection_string", "Server=YourServer;Database=YourDatabase;User ID=YourId;Password=YourPass;CharSet=utf8");
cfg.SetProperty("proxyfactory.factory_class", "NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu");  
cfg.AddAssembly("Your.Assembly.Name");  
ISessionFactory sessionFactory = cfg.BuildSessionFactory();

如果一切正常,如果您愿意,可以将其移至 XML。

关于c# - 配置持久层时出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2407290/

相关文章:

c# - 获取临时键 x 和 y 坐标

c# - 如何确定运行我的应用程序所需的最低 .NET Framework 版本

nhibernate - 如何使用 NHibernate 插入或更新(或覆盖)记录?

c# - 如何禁用菜单项?

c# - 将大文件加载到词典的最佳解决方案

c# - 从 XmlReader 获取流

c# - 用于二维数组的 ASP.NET MVC 5 编辑器

c# - 使用 SendKeys.sendwait() 发送 "spacebar key"

nhibernate - 在投影中重用组件 (NHibernate)

nhibernate - 使用 LINQ to NHibernate 按日期分组