can Dapper implement multiple delete insert or update as QueryMultiple?

dapper

Question

I have seen QueryMultiple from Dapper official doc as below, It is convenient!

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

Now, when I delete record from Parent-table,I want to delete related record from Child-table. can Dapper fit it? It looks that as below.

 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).......... 

Any help will be appreciated!

Popular Answer

Yes, you can can simply call connection.Execute and it already allows multiple commands like you are trying to do, the same as ExecuteQuery allows on SqlCommand, which is all Dapper is calling anyways.



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