NHibernate + SqlServerCE

Sim*_*mon 8 c# nhibernate

我有这个例外的问题:

Hibernate.HibernateException : Could not create the driver from Hibernate.Driver.SqlServerCeDriver.
----> System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
----> NHibernate.HibernateException : The IDbCommand and IDbConnection implementation in the  ssembly System.Data.SqlServerCe could not be found. Ensure that the assembly System.Data.SqlServerCe 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.
Run Code Online (Sandbox Code Playgroud)

我尝试了一切.我google了很多.

System.Data.SqlServerCe.dll位于调试目录中.是本地引用的,不是我的GAC.我复制本地设置为true.在调试目录中是所有其他所需的sql*.dll.我试过x86编译,但没有.

这是我的nhibernate配置:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>

    <property name='proxyfactory.factory_class'>NHibernate.ByteCode.Spring.ProxyFactoryFactory, NHibernate.ByteCode.Spring</property>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="dialect">NHibernate.Dialect.MsSqlCeDialect</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlServerCeDriver</property>

    <property name="show_sql">true</property>


    <!-- mapping files -->

  </session-factory>
</hibernate-configuration>
Run Code Online (Sandbox Code Playgroud)

NHibernate 3.0版beta 1,SqlServerCe版本3.5 SP1

我的想法:Nhibernate仍然在GAC中查看,因为已经安装了SqlServerCe,卸载后问题就开始了.我怎么能对NHibernate说:"请看看这个dll?":)

Joh*_*n C 11

您(或NHibernate dll)在项目中引用的System.Data.SqlServerCe dll的版本不同于预期的版本.例如,NHibernate可能引用了dll的.NET 3.5版本,但是你在GAC或本地bin目录中拥有了.NET 4.0版本的dll.您可以指示.NET框架使用特定的AssemblyBinding来纠正问题.在配置文件中键入以下内容以进行修复.

    <runtime>
    <assemblyBinding 
    xmlns="urn:schemas-microsoft-com:asm.v1"><qualifyAssembly 
   partialName="System.Data.SqlServerCe" fullName="System.Data.SqlServerCe, 
   Version=3.5.1.0, Culture=neutral, 
   PublicKeyToken=89845dcd8080cc91"/>
    </assemblyBinding>
   </runtime> 
Run Code Online (Sandbox Code Playgroud)