无法从 nhibernate.driver.sqlclientdriver、nhibernate、version=5.3.0.0、culture=neutral、publickeytoken=aa95f207798dfdb4 创建驱动程序

could not create the driver from nhibernate.driver.sqlclientdriver, nhibernate, version=5.3.0.0, culture=neutral, publickeytoken=aa95f207798dfdb4

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

错误:无法从 nhibernate.driver.sqlclientdriver 创建驱动程序,nhibernate,version=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();
    }
}

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