编译映射文档时流畅的NHibernate映射异常

时间:2010-07-14 05:26:46

标签: configuration fluent-nhibernate

我有一个NHibernate配置文件如下:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >
  <session-factory name="MyProject">
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="connection.connection_string_name">MyProject</property>
    <property name="connection.isolation">ReadCommitted</property>
    <property name="cache.provider_class">NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache</property>
    <property name="cache.use_second_level_cache">true</property>
    <property name="cache.use_query_cache">true</property>
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
  </session-factory>
</hibernate-configuration>

创建配置对象时:

Configuration cfg = new Configuration();
cfg.AddFile(nhibernateConfigurationFile);

尝试运行持久性测试时出现以下错误:

  • System.InvalidOperationException:在配置中找不到方言

  • NHibernate.MappingException:无法编译映射文档:C:\ PathToProject \ bin \ Debug \ NHibernateMyProject.config

任何人都知道为什么它在阅读nhibernate配置文件时遇到问题?从我能够看到的,方言肯定在配置....

1 个答案:

答案 0 :(得分:0)

你应该使用这个方言:NHibernate.Dialect.MsSql2000Dialect

尝试定义包含映射文件的程序集:

<mapping assembly="yourAssembly"/>

对于配置文件:

new Configuration().Configure( yourfile.cfg.xml );