0

我正在使用SqlKata来执行数据库查询。

这就是我想要做的:

var task1= GetData(id);
var task2 = HasPrivilege(Id);
await Task.WhenAll(task1, task2);
var data = await task1;
var hasPrivilege = await task2;

但我收到以下错误:

InvalidOperationException:BeginExecuteNonQuery 需要打开且可用的连接

我已经注册了 SqlKata QueryFactory,如下所示:

services.AddTransient(provider =>
{
    var connection = new SqlConnection(Configuration.GetConnectionString("DefaultConnection"));
    var compiler = new SqlServerCompiler();
    var queryFactory = new QueryFactory(connection, compiler);
    queryFactory.Logger = compiled => Console.WriteLine(compiled.ToString());
    return queryFactory;
});
4

0 回答 0