我用 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 中我们应该使用 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
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 http://intellect.dk/post/Why-I-love-frameworks-with-lots-of-extension-points.aspx )
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)