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

标签 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" >
        <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.Data.SQLite。

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

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

有人知道如何进行吗?

最佳答案

您需要让 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 )

关于c# - 尝试将 Nhibernate 与 Mono 和 SQLite 一起使用 - 找不到 System.Data.SQLite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6203597/

相关文章:

c# - .NET 日期添加天数

c# - 如何在遍历树结构时匹配路径

c# - WCF REST 与 WEB API 之间的区别

c# - 如何在 Prism wpf 模块化应用程序中首先使用代码动态创建数据库表?

ios - FMDB executeUpdate DROP 命令确实停止了应用程序

c# - 使用 [Authorize] 时请求超过配置的 maxQueryStringLength

nhibernate - 在 nHibernate : "Index was out of range." 中更新时出错

nhibernate - Basic Fluent NHibernate 程序编译并运行,但没有保存到数据库或从数据库加载任何内容

NHibernate 代理 ID 值

ios - 在sqlite中创建带有外键的表