CancellationToken with async Dapper methods?

前端 未结 4 1659
不思量自难忘°
不思量自难忘° 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:44

    try using a SqlConnection and catch the exception on cancel

    var sqlConn = db.Database.Connection as SqlConnection;
    sqlConn.Open();
    
    _cmd = new SqlCommand(textCommand, sqlConn);
    _cmd.ExecuteNonQuery();
    

    and cancel the SqlCommand

    _cmd.Cancel();
    

提交回复
热议问题