简体   繁体   English

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

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

I wrote a simple app in mono (C#) that uses NHibernate with MYSQL - and I now want to port it to SQLite.我在 mono (C#) 中写了一个简单的应用程序,它使用 NHibernate 和 MYSQL - 我现在想将它移植到 Z4977757A9C70B51EC1

My hope is (was) that I could simply change hibernate.cfg.xml and point it to a different database.我的希望是(曾经)我可以简单地更改 hibernate.cfg.xml 并将其指向不同的数据库。 Here is my modified 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> 

The problem is that I'm getting an error to the effect that it can't find System.Data.SQLite.问题是我收到一个错误,它无法找到 System.Data.SQLite。 This doesn't surprise me since, as I understand it, in mono we should be using Mono.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. 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.

This is all being done on Linux - if that makes any difference.这一切都在 Linux 上完成 - 如果这有什么不同的话。

Does anyone have any ideas how to proceed?有谁知道如何进行?

You need to make nHibernate aware of the Mono.Data.SQLite assembly.您需要让 nHibernate 了解 Mono.Data.SQLite 程序集。 Add this to the configuration:将此添加到配置中:

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

And you also need a simple MonoSQLiteDriver class:你还需要一个简单的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;  
        }  
    }  
}  

(code taken from http://intellect.dk/post/Why-I-love-frameworks-with-lots-of-extension-points.aspx ) (代码取自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 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