SQL Lite on NHibernate

   一直为在单元测试中测试mapping很纠结。现在用SQL Lite,不纠结了。

   首先这里SQL Lite,然后编写config文件,如下

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory name="NHibernate.Test">
    <property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property>   
    <property name="connection.connection_string">
      Data Source=a.db;Version=3;New=true
    </property>
    <property name="show_sql">true</property>
    <property name="dialect">NHibernate.Dialect.SQLiteDialect</property>    
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory,NHibernate.ByteCode.LinFu</property>        
    <mapping assembly="Ornament.MemberShip.Core" />    
  </session-factory>
</hibernate-configuration>

    其中,要留意一下driver_class项,如果使用我提供的SQL Lite,就必须使用 NHibernate.Driver.SQLite20Driver。如果你是下载SQL lite msi安装包,默认会把SQL Lite 放到GAC里面,那么测试项目中就需要设定<qualifyAssembly> 元素,又或者引用System.Data.SQLLite.dll后,把copy local 设定为true。否则就会出现以下异常

NHibernate.HibernateException: The IDbCommand and IDbConnection implementation in the assembly System.Data.SQLite could not be found. Ensure that the assembly System.Data.SQLite is located in the application directory or in the Global Assembly Cache. If the assembly is in the GAC, use <qualifyAssembly/> element in the application configuration file to specify the full name of the assembly..

原文地址:https://www.cnblogs.com/fantasylu/p/1722049.html