Trying to using Nhibernate with Mono amp; SQLite - can#39;t find System.Data.SQLite(尝试将 Nhibernate 与 Mono amp;SQLite - 找不到 System.Data.SQLite)
问题描述
我用单声道 (C#) 编写了一个简单的应用程序,它使用 NHibernate 和 MYSQL - 现在我想将它移植到 SQLite.
I wrote a simple app in mono (C#) that uses NHibernate with MYSQL - and I now want to port it to SQLite.
我希望(曾经)我可以简单地更改 hibernate.cfg.xml 并将其指向不同的数据库.这是我修改后的hibernate.cfg.xml:
My hope is (was) that I could simply change hibernate.cfg.xml and point it to a different database. Here is my modified 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.
The problem is that I'm getting an error to the effect that it can't find System.Data.SQLite. This doesn't surprise me since, as I understand it, in mono we should be using Mono.Data.SQLite.
问题是(假设我正确理解了问题)我不知道如何告诉 NHibernate 使用 Mono.Data.SQLite 而不是 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.
这一切都是在 Linux 上完成的——如果这有什么不同的话.
This is all being done on Linux - if that makes any difference.
有人知道如何进行吗?
推荐答案
您需要让 nHibernate 了解 Mono.Data.SQLite 程序集.将此添加到配置中:
You need to make nHibernate aware of the Mono.Data.SQLite assembly. Add this to the configuration:
<add key="connection.driver_class" value="Name.Space.MonoSqliteDriver, AssemblyName" />
而且你还需要一个简单的 MonoSQLiteDriver
类:
And you also need a simple 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 )
这篇关于尝试将 Nhibernate 与 Mono &SQLite - 找不到 System.Data.SQLite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:尝试将 Nhibernate 与 Mono &SQLite - 找不到 System.Data.SQLite
基础教程推荐
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01