I'm trying to delete from two tables with two different vairables within ac# 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.
The second operation should use Execute, not Query. It isn't a query, basically. That should be all you need.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.