dapper.net多重删除问题

CSh*_*Bee 2 c# dapper micro-orm

我正在尝试从ac#class中的两个不同的vairables中删除两个表,但是我收到以下错误消息:

使用多映射API时,如果您具有Id参数名称以外的键,请确保设置splitOn参数:splitOn

通过SQL事件探查器捕获命令时,sql语句执行正常,所以我很难过.

精巧的代码是:

 public void DeleteListCode(string listCodeId)
    {
       using (var block = new TransactionBlock())
       {
           // Get the code first
           const string sql = "SELECT ListCode from ListCodes WHERE id =@listCodeId";
           var code = TransactionBlock.Connection.Query<string>(sql, new {listCodeId}, TransactionBlock.Transaction)
              .FirstOrDefault();

           if (string.IsNullOrEmpty(code)) return;

           const string sql2 = "delete from Lists WHERE ListCode = @code " +
                               "delete from ListCodes where Id = @listCodeId";

            TransactionBlock.Connection.Query(sql2, new {listCodeId, code}, TransactionBlock.Transaction);
           block.Commit();
       }
    }
Run Code Online (Sandbox Code Playgroud)

我已成功设法使用多选语句,但这在我使用两个自治参数的意义上略有不同.

Mar*_*ell 6

第二个操作应该使用Execute,而不是Query.它基本上不是一个查询.这应该就是你所需要的.

  • @MeerDeen `connection.Execute("... where Id in @ids ...", new { ids });` (3认同)