错误提示:System.InvalidOperationException: Could not find the dialect in the configuration在网上查了N久资料,好像是版本错误。但是我都核对了,应该没错啊。NHibernate.dll 2.0的版的User.hbm.xml配置文件
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="NHbe.entity.User, entity.User" table="users">
<id name="Id" column="LogonId" type="String" length="20">
<generator class="assigned" />
</id>
<property name="UserName" column="Name" type="String" length="40"/>
<property name="Password" type="String" length="20"/>
<property name="EmailAddress" type="String" length="40"/>
<property name="LastLogon" type="DateTime"/>
</class>
</hibernate-mapping>web.config 配置文件<configSections>
<section name="nhibernate"
type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections> <nhibernate>
<add
key="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvider"/>
<add
key="hibernate.dialect"
value="NHibernate.Dialect.MsSql2000Dialect"/>
<add
key="hibernate.connection.driver_class"
value="NHibernate.Driver.SqlClientDriver"/>
<add
key="hibernate.connection.connection_string"
value="server=.\DB05;uid=sa;pwd=123456;database=MyDB"/>
</nhibernate>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="NHbe.entity.User, entity.User" table="users">
<id name="Id" column="LogonId" type="String" length="20">
<generator class="assigned" />
</id>
<property name="UserName" column="Name" type="String" length="40"/>
<property name="Password" type="String" length="20"/>
<property name="EmailAddress" type="String" length="40"/>
<property name="LastLogon" type="DateTime"/>
</class>
</hibernate-mapping>web.config 配置文件<configSections>
<section name="nhibernate"
type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections> <nhibernate>
<add
key="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvider"/>
<add
key="hibernate.dialect"
value="NHibernate.Dialect.MsSql2000Dialect"/>
<add
key="hibernate.connection.driver_class"
value="NHibernate.Driver.SqlClientDriver"/>
<add
key="hibernate.connection.connection_string"
value="server=.\DB05;uid=sa;pwd=123456;database=MyDB"/>
</nhibernate>
<xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler" /> configSections> <nhibernate> <add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" /> <add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect" /> <add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" /> <add key="hibernate.connection.connection_string" value="Server=localhost;uid=sa;password=sa;database=NHTrial" /> </nhibernate><configuration>然后,我们在程序中只需简单的初始化Configuration对象即可。Configuration cfg = new Configuration();
0 少了dialect属性设置
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory >
<property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string"></property>
<mapping assembly="Entity" />
</session-factory>
</hibernate-configuration>
参考