2011-06-01 65 views
6

我写了一个简单的应用程序在单一(C#),使用NHibernate与MYSQL - 我现在想要将它移植到SQLite。试图使用Nhibernate与单声道和SQLite - 无法找到System.Data.SQLite

我的希望是(我)可以简单地更改hibernate.cfg.xml并将其指向不同的数据库。这是我修改的hibernate.cfg.xml:

<?xml version="1.0" encoding="utf-8" ?> 

    <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=nhibernate_test.db;Version=3 
      </property> 
      <property name="dialect">NHibernate.Dialect.SQLiteDialect</property> 
      <property name="query.substitutions">true=1;false=0</property> 
      <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property> 
     </session-factory> 

</hibernate-configuration> 

的问题是,我得到一个错误,它无法找到System.Data.SQLite的效果。这并不让我感到意外,因为据我所知,在mono中,我们应该使用Mono.Data.SQLite。

麻烦是(假设我正确理解问题)我不知道如何告诉NHibernate使用Mono.Data.SQLite而不是System.Data.SQLite。

这一切都在Linux上完成 - 如果这有什么区别。

有没有人有任何想法如何进行?

回答

8

您需要让nHibernate意识到Mono.Data.SQLite程序集。这增加了配置:

<add key="connection.driver_class" value="Name.Space.MonoSqliteDriver, AssemblyName" /> 

而且你还需要一个简单MonoSQLiteDriver类:

public class MonoSqliteDriver : NHibernate.Driver.ReflectionBasedDriver 
{ 
    public MonoSqliteDriver() : 
     base("Mono.Data.Sqlite", 
     "Mono.Data.Sqlite.SqliteConnection", 
     "Mono.Data.Sqlite.SqliteCommand") 
    { 
    } 
    public override bool UseNamedPrefixInParameter { 
     get { 
      return true; 
     } 
    } 
    public override bool UseNamedPrefixInSql { 
     get { 
      return true; 
     } 
    } 
    public override string NamedPrefix { 
     get { 
      return "@"; 
     } 
    } 
    public override bool SupportsMultipleOpenReaders { 
     get { 
      return false; 
     } 
    } 
} 

(代码http://intellect.dk/post/Why-I-love-frameworks-with-lots-of-extension-points.aspx拍摄)

+0

谢谢 - 这看起来像是一个很好的解决方案,尽管我不能似乎找出它应该去的配置中的下落... – 2011-06-02 16:50:04

+0

没关系 - 我想我已经想通了:-) – 2011-06-02 17:07:09

+0

嗯,你能澄清它应该去哪里?我自己也遇到了问题:-) – skolima 2011-06-03 08:11:55