尝试将Nhibernate与Mono和SQLite一起使用 - 找不到System.Data.SQLite

Pau*_*ett 7 c# sqlite nhibernate mono

我用单声道(C#)编写了一个简单的应用程序,它使用NHibernate和MYSQL - 现在我想把它移植到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> 
Run Code Online (Sandbox Code Playgroud)

问题是我收到一个错误,它无法找到System.Data.SQLite.这并不让我感到惊讶,因为据我所知,单声道我们应该使用Mono.Data.SQLite.

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

这一切都是在Linux上完成的 - 如果这有任何区别的话.

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

sko*_*ima 9

您需要让nHibernate知道Mono.Data.SQLite程序集.将其添加到配置中:

<add key="connection.driver_class" value="Name.Space.MonoSqliteDriver, AssemblyName" />
Run Code Online (Sandbox Code Playgroud)

而且你还需要一个简单的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;  
        }  
    }  
}  
Run Code Online (Sandbox Code Playgroud)

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