【问题标题】:could not create the driver from nhibernate.driver.sqlclientdriver, nhibernate, version=5.3.0.0, culture=neutral, publickeytoken=aa95f207798dfdb4无法从 nhibernate.driver.sqlclientdriver、nhibernate、version=5.3.0.0、culture=neutral、publickeytoken=aa95f207798dfdb4 创建驱动程序
【发布时间】:2021-12-30 17:32:29
【问题描述】:

我在 .net 6 项目中遇到以下错误 fluentNhibernate,但相同的代码在框架 4.8 中运行。

错误:无法从 nhibernate.driver.sqlclientdriver 创建驱动程序,nhibernate,版本=5.3.0.0,culture=neutral,publickeytoken=aa95f207798dfdb4

我在 .net 6 中的代码是:

public class DatabaseContext
{
    private static ISessionFactory session;

    private static ISessionFactory CreateSession()
    {
        const string connectionString = "Data source=SQLEXPRESS;Database=**;Integrated Security=True";

        if (session != null)
        {
            return session;
        }
        var sqlConfiguration = MsSqlConfiguration.MsSql2012.ConnectionString(connectionString);

        return Fluently.Configure()
            .Database(sqlConfiguration)
            .Mappings(m => m.FluentMappings.AddFromAssemblyOf<TokenMapping>())
            .ExposeConfiguration(cfg => new SchemaExport(cfg).Execute(false, true, false))
            .BuildSessionFactory();
    }
    public static NHibernate.ISession SessionOpen()
    {
        return CreateSession().OpenSession();
    }
}

【问题讨论】:

    标签: nhibernate fluent-nhibernate nhibernate-mapping


    【解决方案1】:

    您需要将 nuget 包 System.Data.SqlClient 添加到您的项目中,以使 NHibernate.Driver.SqlClientDriver 在 .NET Core 下工作。

    【讨论】:

    • 非常感谢兄弟,那天晚上我发现了问题,而不是安装包。
    猜你喜欢
    • 1970-01-01
    • 2016-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-14
    相关资源
    最近更新 更多