我阅读并实施了Trying to using Nhibernate with Mono & SQLite - can't find System.Data.SQLite 但是,正如最后一条评论所说,这似乎不适用于NHibernate 3.1
错误是
HibernateException:中的IDbCommand和IDbConnection实现 找不到程序集Mono.Data.Sqlite。确保 程序集Mono.Data.Sqlite是[...可达...]
我在GAC中有Mono.Data.Sqlite
我已经尝试将“Mono.Data.Sqlite”和typeof(Mono.Data.Sqlite.SqliteConnection).Assembly.FullName
都指定为程序集的名称
有没有人想过如何让这个工作?
答案 0 :(得分:7)
Trying to using Nhibernate with Mono & SQLite - can't find System.Data.SQLite的答案存在问题。 要使给定的构造函数(3个参数)起作用,需要首先加载有问题的程序集(Mono.Data.Sqlite)。
如果使用4参数基本构造函数,则此方法有效:
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 - 谢谢。)
如果您使用FluentNHibernate,那么您还需要:
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)));
}
}
到目前为止我没有遇到任何问题......