我从 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();
...
}
现在,当我从父表中删除记录时,我想从子表中删除相关记录。Dapper 能适应吗?它看起来如下。
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)..........
任何帮助将不胜感激!