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!
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 .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With