CancellationToken with async Dapper methods?

前端 未结 4 1657
不思量自难忘°
不思量自难忘° 2020-12-28 12:56

I\'m using Dapper 1.31 from Nuget. I have this very simple code snippet,

string connString = \"\";
string query = \"\";
int val = 0;
CancellationTokenSource          


        
4条回答
  •  时光说笑
    2020-12-28 13:35

    You can fix SqlMapper.cs in Dapper lib by adding these lines:

        internal IDbCommand SetupCommand(IDbConnection cnn, Action paramReader)
        {
            var cmd = cnn.CreateCommand();
    
    #if ASYNC
            // We will cancel our IDbCommand
            CancellationToken.Register(() => cmd.Cancel());
    #endif
    

    Rebuild your own Dapper lib and enjoy :)

提交回复
热议问题