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.
Execute
rather thanQuery
.sql
variable once you have executed that query have you thought about executing aRollBack
command since on the select you're only returning data and not changing data..? then execute the second statement just as you are doing..? or split the sql2 string into 2 different transactions.. also I think that petelids has a good point try doing something like thisTransactionBlock.Connection.Execute
instead