簡體   English   中英

嘗試將 Nhibernate 與 Mono 和 SQLite 一起使用 - 找不到 System.Data.Z497757A9C5B2EC178DEDZ6

[英]Trying to using Nhibernate with Mono & SQLite - can't find System.Data.SQLite

我在 mono (C#) 中寫了一個簡單的應用程序,它使用 NHibernate 和 MYSQL - 我現在想將它移植到 Z4977757A9C70B51EC1

我的希望是(曾經)我可以簡單地更改 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。

The trouble is (assuming I'm understanding the problem correctly) I don't know how to tell NHibernate to use Mono.Data.SQLite instead of System.Data.SQLite.

這一切都在 Linux 上完成 - 如果這有什么不同的話。

有誰知道如何進行?

您需要讓 nHibernate 了解 Mono.Data.SQLite 程序集。 將此添加到配置中:

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

你還需要一個簡單的MonoSQLiteDriver class:

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

Note that you might need to use 4 parameters instead of 3 for the call to the constructor of the ReflectionBasedDriver base class, see Using NHibernate and Mono.Data.Sqlite

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM