Dapper Plus - Bulk Delete

Dapper Plus - Bulk Delete

 

Description

DELETE entities using Bulk Operation.

 

Example - Delete Single

DELETE a single entity with Bulk Operation.

DapperPlusManager.Entity<Customer>().Table("Customers").Key("CustomerID");

using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServerW3Schools()))
{
	connection.BulkDelete(connection.Query<Customer>("Select * FROM CUSTOMERS WHERE CustomerID in (53,57) ").ToList());
}

Try it online

 

Example - Delete Many

DELETE many entities with Bulk Operation.

DapperPlusManager.Entity<Customer>().Table("Customers").Key("CustomerID");

using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServerW3Schools()))
{
	connection.BulkDelete(connection.Query<Customer>("Select * FROM CUSTOMERS WHERE CustomerID in (53,57) ").ToList());
}

Try it online

 

Example - Delete with relation (One to One)

DELETE entities with a one to one relation with Bulk Operation.

DapperPlusManager.Entity<Supplier>().Table("Suppliers").Identity(x => x.SupplierID);
DapperPlusManager.Entity<Product>().Table("Products").Identity(x => x.ProductID);

using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServerW3Schools()))
{
	connection.BulkDelete(suppliers.Select(x => x.Product)).BulkDelete(suppliers);
}

Try it online

 

Example - Delete with relation (One to Many)

DELETE entities with a one to many relation with Bulk Operation.

DapperPlusManager.Entity<Supplier>().Table("Suppliers").Identity(x => x.SupplierID);
DapperPlusManager.Entity<Product>().Table("Products").Identity(x => x.ProductID);

using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServerW3Schools()))
{
	connection.BulkDelete(suppliers.SelectMany(x => x.Products)).BulkDelete(suppliers);
}

Try it online

發佈了10 篇原創文章 · 獲贊 1 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章