Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can Dapper implement multiple delete insert or update as QueryMultiple?

Tags:

dapper

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!

like image 880
Kevin Auds Avatar asked Oct 05 '12 03:10

Kevin Auds


People also ask

What is splitOn in dapper?

splitOn: CustomerId will result in a null customer name. If you specify CustomerId,CustomerName as split points, dapper assumes you are trying to split up the result set into 3 objects. First starts at the beginning, second starts at CustomerId , third at CustomerName .


1 Answers

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.

like image 199
bkaid Avatar answered Oct 02 '22 23:10

bkaid