dapper.net multiple delete issue

c# dapper micro-orm

Question

I'm trying to delete from two tables with two different vairables within a c# class, but I get the following error message:

When using the multi-mapping APIs ensure you set the splitOn param if you have keys other than Id Parameter name: splitOn

The sql statement executes fine when capturing command via SQL Profiler, so I'm stumped.

The dapper code is:

 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();
       }
    }

I've successfully managed to use a multi select statement, but this is slightly different in the sense that I use two annonomous parameters.

Accepted Answer

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



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why