我对NHibernate完全不熟悉。我看到许多问题具有相同的标题,但我无法找到确切的错误。我在SQL Server 2012中使用NHibernate。
我的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="dialect">NHibernate.Dialect.MsSql2012Dialect</property>
<property name="connection.connection_string">Data Source=.\SQLEXPRESS;Initial Catalog=cafePOSdb;Integrated Security=True;</property>
<property name="show_sql">true</property>
<mapping assembly="CafePOS" />
</session-factory>
</hibernate-configuration>
我的地图模型:
using System;
using System.Text;
using System.Collections.Generic;
namespace CafePOS
{
public class CafeTableGroup
{
//properties here
}
}
我的hbm.xml
文件:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping assembly="CafePOS" namespace="CafePOS" xmlns="urn:nhibernate-mapping-2.2">
<class name="cafe_table_group" table="cafe_table_group" lazy="true" >
<!--properties here -->
</class>
</hibernate-mapping>
我的SessionFactory类:
namespace XXXXXX
{
public sealed class SessionFactory
{
private static volatile ISessionFactory iSessionFactory;
private static object syncRoot = new Object();
public static ISession OpenSession
{
get
{
if (iSessionFactory == null)
{
lock (syncRoot)
{
if (iSessionFactory == null)
{
Configuration configuration = new Configuration();
Assembly assembly = Assembly.GetCallingAssembly();
configuration.AddAssembly(assembly);
iSessionFactory = configuration.BuildSessionFactory();
}
}
}
return iSessionFactory.OpenSession();
}
}
}
}
这是我试图实现的功能:
public static string Add(CafeTableGroup group)
{
using (ISession session = SessionFactory.OpenSession)
{
using (ITransaction transaction = session.BeginTransaction())
{
try
{
session.Save(group);
transaction.Commit();
return "1";
}
catch (Exception ex)
{
transaction.Rollback();
session.Close();
throw ex.InnerException;
}
}
}
}
我在行上收到错误
configuration.AddAssembly(assembly);
显示标题中的错误:
无法编译映射文档:NHibernate
内部异常消息:
无法在配置中找到方言
提前致谢。
答案 0 :(得分:1)
您的班级名称不是cafe_table_group
,而是CafeTableGroup
。
您可以尝试将hbm.xml
更改为
<class name="CafeTableGroup" table="cafe_table_group" lazy="true">
**************
答案 1 :(得分:0)
你应该在根文件夹中有文件hibernate.cfg.xml。
该文件的示例内容为:
$(document).on('click', 'a', function(event){
event.preventDefault();
...
});