我从Dapper官方文档中看过如下的QueryMultiple,很方便!
var sql = @"
select * from Customers where CustomerId = @id
select * from Orders where CustomerId = @id
select * from Returns where CustomerId = @id";
using (var multi = connection.QueryMultiple(sql, new {id=selectedId}))
{
var customer = multi.Read<Customer>().Single();
var orders = multi.Read<Order>().ToList();
var returns = multi.Read<Return>().ToList();
...
}
现在,当我从Parent-table中删除记录时,我想从Child-table中删除相关记录。 小巧玲珑的适合吗?看起来如下所示。
var sql = @"delete from tb_role where roleid=@ID
delete from tb_rolepermission where roleid=@ID
delete from tb_userrole where roleid=@ID
";
var param = new { ID=id };
connection.EXECUTEMultiple(sql, param)..........
任何帮助将不胜感激!
答案 0 :(得分:4)
是的,您可以简单地调用connection.Execute并且它已经允许您尝试执行的多个命令,就像ScuteCommand上的ExecuteQuery允许的那样,这都是Dapper正在调用的。