使用 NHibernate 和 Mono.Data.SQLite

发布于 2024-12-07 09:16:47 字数 576 浏览 0 评论 0原文

我阅读并实现了 尝试使用 Nhibernate与单声道和SQLite - 找不到 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 作为程序集的名称

有没有人有任何想法如何得到这个在职的?

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

The error is

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...]

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

残疾 2024-12-14 09:16:47

的答案有问题尝试将 Nhibernate 与 Mono & 一起使用SQLite - 找不到 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)));
    }
}

到目前为止我还没有遇到任何问题......

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.

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;  
        }  
    }  
}  

(Still, credit goes to http://intellect.dk/post/Why-I-love-frameworks-with-lots-of-extension-points.aspx for the original idea - thanks.)

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文