我收到错误"无法在配置中找到方言"当我尝试运行我的第一个Nhibernet应用程序时。我将app.config文件保存为嵌入式资源,并将.hbm.xml
保存为嵌入式资源。如果我保持我的app.config不复制,那么错误到达No Persister for:class file。
以下是我的文件,首先是Customers.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Nhibernate_Demo
{
public class Customers
{
public virtual int id { get; set; }
public virtual string name { get; set; }
public virtual string city { get; set; }
}
}
Customers.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Nhibernate_Demo.Customers, Nhibernate_Demo" table="Customers">
<id name="id" column="customer_id" type="int">
<generator class="assigned" />
</id>
<property name="name" column="customer_name" type="String" length="30"/>
<property name="city" column="city" type="String" length="30"/>
</class>
</hibernate-mapping>
app.config文件
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
</configSections>
<!--NHibernate Configuration (Adding Properties)-->
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory>
<property name="dialect">
NHibernate.Dialect.MsSql2012Dialect
</property>
<property name="connection.provider">
NHibernate.Connection.DriverConnectionProvider
</property>
<property name="connection.driver_class">
NHibernate.Driver.SqlClientDriver
</property>
<property name="connection.connection_string">
Server=localhost;
Database=Practice;
Integrated Security=True;
</property>1
<mapping assembly="Nhibernate_Demo"></mapping>
</session-factory>
</hibernate-configuration>
</configuration>
我正在使用以下环境: