使用NHibernate和Mono.Data.SQLite [英] Using NHibernate and Mono.Data.SQLite
问题描述
我阅读并实现了尝试将Nhibernate与Mono&结合使用SQLite-找不到System.Data.SQLite 但是,正如最后的评论所述,这似乎不适用于NHibernate 3.1
I read and implemented Trying to using Nhibernate with Mono & SQLite - can't find System.Data.SQLite However, as the last comment there states this seems not to work with NHibernate 3.1
错误是
HibernateException:IDbCommand和IDbConnection实现在 找不到程序集Mono.Data.Sqlite.确保 程序集Mono.Data.Sqlite是[... reachable ...]
HibernateException: The IDbCommand and IDbConnection implementation in the assembly Mono.Data.Sqlite could not be found. Ensure that the assembly Mono.Data.Sqlite is [...reachable...]
我在GAC中有Mono.Data.Sqlite.
我尝试同时指定"Mono.Data.Sqlite"和typeof(Mono.Data.Sqlite.SqliteConnection).Assembly.FullName
作为程序集的名称
I have Mono.Data.Sqlite in the GAC.
I have tried both specifying "Mono.Data.Sqlite" as well as typeof(Mono.Data.Sqlite.SqliteConnection).Assembly.FullName
as the name of the assembly
有人对如何使它起作用有任何想法吗?
Has anyone any Ideas how to get this working?
推荐答案
There is a problem in the answer of Trying to using Nhibernate with Mono & SQLite - can't find System.Data.SQLite . For the given constructor (3 parameters) to work the assembly in question (Mono.Data.Sqlite) needs to be loaded first.
如果像这样使用4参数基本构造器,这将起作用:
This works if the 4-parameter base contructor is used like this:
public class MonoSQLiteDriver : NHibernate.Driver.ReflectionBasedDriver
{
public MonoSQLiteDriver()
: base(
"Mono.Data.Sqlite",
"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 作为原始想法-谢谢.)
(Still, credit goes to http://intellect.dk/post/Why-I-love-frameworks-with-lots-of-extension-points.aspx for the original idea - thanks.)
如果您使用FluentNHibernate,那么您还需要:
And if you use FluentNHibernate, then you'll also need:
public class MonoSQLiteConfiguration : PersistenceConfiguration<MonoSQLiteConfiguration>
{
public static MonoSQLiteConfiguration Standard
{
get { return new MonoSQLiteConfiguration(); }
}
public MonoSQLiteConfiguration()
{
Driver<MonoSQLiteDriver>();
Dialect<SQLiteDialect>();
Raw("query.substitutions", "true=1;false=0");
}
public MonoSQLiteConfiguration InMemory()
{
Raw("connection.release_mode", "on_close");
return ConnectionString(c => c
.Is("Data Source=:memory:;Version=3;New=True;"));
}
public MonoSQLiteConfiguration UsingFile(string fileName)
{
return ConnectionString(c => c
.Is(string.Format("Data Source={0};Version=3;New=True;", fileName)));
}
public MonoSQLiteConfiguration UsingFileWithPassword(string fileName, string password)
{
return ConnectionString(c => c
.Is(string.Format("Data Source={0};Version=3;New=True;Password={1};", fileName, password)));
}
}
到目前为止,我还没有遇到任何问题...
I have not encountered any problems so far...
这篇关于使用NHibernate和Mono.Data.SQLite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!