2

我正在尝试从 ac# 类中具有两个不同变量的两个表中删除,但我收到以下错误消息:

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

通过 SQL Profiler 捕获命令时 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();
       }
    }

我已经成功地使用了多选语句,但这在我使用两个匿名参数的意义上略有不同。

4

1 回答 1

9

The second operation should use Execute, not Query. It isn't a query, basically. That should be all you need.

于 2014-08-13T17:10:09.087 回答