c# – Dapper Bulk时出错. “你必须明确设置提供者”

我正在创建一个从Firebird到SQL Server的同步应用程序.

我正在使用Dapper Plus的BulkInsert.

var fbClient = new FirebirdConnect();
using (var source = fbClient.GetConnection())
{

    if (source.State == ConnectionState.Closed)
        source.Open();

    var sqlClient = new AzureConnect();
    using (var target = sqlClient.GetConnection())
    {
        if (target.State == ConnectionState.Closed)
            target.Open();

        var lastUpdate = connection.Query<DateTime>($"select coalesce((select max(DateSyncTarget) from {metadados.TargetName}), getdate()-10000) LastUpdate").ToList();

        var resultSource = source.Query<MyClass>("select * from MyClass");

        target.BulkInsert(resultSource.Where(w => w.Data > lastUpdate[0]));

        var resultTargert = target.Query<MyClassSource>("select * from MyClass")

        source.BulkInsert(resultTargert.Where(w => w.Data > lastUpdate[0]));//Error here

    }
}

当我咨询源以在目标中插入时,一切都很顺利.

但是当我查询目标插入源时,它会给出以下错误:

The Provider could not be resolved. You must explicity set the
Provider.

有什么原因导致错误?

编辑:

全栈:

   em ..(BulkOperation )
   em ..(BulkOperation )
   em Z.BulkOperations.BulkOperation.BulkInsert()
   em Z.Dapper.Plus.DapperPlusAction.Execute()
   em Z.Dapper.Plus.DapperPlusAction..ctor(BaseDapperPlusActionSet action, String key, DapperPlusActionKind kind, Object dataSource)
   em Z.Dapper.Plus.DapperPlusActionSet`1.AddAction(String mapperKey, DapperPlusActionKind actionKind, TEntity item)
   em Z.Dapper.Plus.DapperPlusActionSet`1.DapperPlusActionSetBuilder(IDbConnection connection, IDbTransaction transaction, String mapperKey, DapperPlusActionKind actionKind, TEntity item, Func`2[] selectors)
   em Z.Dapper.Plus.DapperPlusExtensions.BulkInsert[T](IDbConnection connection, String mapperKey, T item, Func`2[] selectors)
   em Z.Dapper.Plus.DapperPlusExtensions.BulkInsert[T](IDbConnection connection, T item, Func`2[] selectors)
   em Project.Plugins.Utils.Extensions.CommandExtensions.InsertSource[T](IDbConnection connection, IEnumerable result) na D:\Projetos\Project-API-Cloud\project-etl\Project.Plugins.Utils\Extensions\CommandExtensions.cs:linha 52
   em Autorizacoes.ERP.LIBSENHA.JobAutorizacoes.Execute(IJobExecutionContext context) na D:\Projetos\Project-API-Cloud\Project-etl\Autorizacoes\JobAutorizacoes.cs:linha 105

最佳答案 免责声明:我是 Dapper Plus项目的所有者

问题

Dapper Plus库引发以下错误:

The Provider could not be resolved. You must explicity set the
Provider.

原因

Dapper Plus无法从提供的连接中找到提供商.

例如,连接可能类似​​于AzureConnection.

var sqlClient = new AzureConnect();
var target = sqlClient.GetConnection()
var fullName = target.GetType().FullName;

该库目前不知道它必须以与SqlConnection相同的方式处理此连接.

解决方案#1 – SqlConnection Direct

请直接使用SqlConnection.

如果当前连接只是一个包装器,您可能会在有时名为UnderlyingConnection或InnerConnection的属性下找到SqlConnection.

解决方案#2 – 报告问题

我建议你打开一个问题here

并提供有关如何使用/下载内容的信息,以便我们可以使用与AzureConnect相同的代码.

我们通常会在几天内解决这类问题.

点赞