Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 尝试将Nhibernate与Mono&;SQLite-can';找不到System.Data.SQLite_C#_Nhibernate_Sqlite_Mono - Fatal编程技术网

C# 尝试将Nhibernate与Mono&;SQLite-can';找不到System.Data.SQLite

C# 尝试将Nhibernate与Mono&;SQLite-can';找不到System.Data.SQLite,c#,nhibernate,sqlite,mono,C#,Nhibernate,Sqlite,Mono,我用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"

我用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> 

NHibernate.Driver.SQLite20Driver
数据源=nhibernate_test.db;版本=3
NHibernate.dialogue.sqlitedialogue
真=1;假=0
NHibernate.ByteCode.LinFu.ProxyFactoryFactory,NHibernate.ByteCode.LinFu
问题是我得到了一个错误,大意是它找不到System.Data.SQLite。这并不奇怪,因为据我所知,在mono中我们应该使用mono.Data.SQLite

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

这一切都是在Linux上完成的——如果这有什么不同的话


有人知道如何继续吗?

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

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

(代码取自)

注意,您可能需要使用4个参数而不是3个参数来调用ReflectionBasedDriver基类的构造函数,请参见

谢谢-这看起来是一个很好的解决方案,尽管我似乎无法确定它应该在配置中的位置……嗯,您能澄清它应该放在哪里吗?我自己也有问题:-)是的-我在同一个解决方案中将上面的类添加到一个程序集项目中,然后您只需将FirstNHibernate.MonoSqliteDriver、MonoSqliteDriver添加到hibernate配置中-根据需要调整命名空间/程序集名称:-)我在NHibernate 3.0中尝试过它,但在这里不起作用。它无法搜索该程序集中的IDb*接口。您使用的是哪个版本?@ikutsin,我在使用4参数化的基本构造函数时取得了更好的进展(只需将第一个参数加倍)-这样,使用中的程序集就不必以前加载。。。
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;  
        }  
    }  
}