Dapper Plus - Bulk Merge

Dapper Plus - Bulk Merge

 

Description

MERGE entities using Bulk Operation.

  • Merge single
  • Merge many
  • Merge with relation (One to One)
  • Merge with relation (One to Many)

 

Example - Merge Single

MERGE a single entity with Bulk Operation.

DapperPlusManager.Entity().Table("Customers"); 

using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServerW3Schools()))
{
	connection.BulkMerge(new List() { new Customer() { CustomerName = "ExampleBulkMerge", ContactName = "Example Name :" +  1}});
}

Try it online

 

Example - Merge Many

MERGE many entities with Bulk Operation.

DapperPlusManager.Entity().Table("Customers"); 

using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServerW3Schools()))
{
	connection.BulkMerge(customers);
}

Try it online

 

Example - Merge with relation (One to One)

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

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

using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServerW3Schools()))
{	
	connection.BulkMerge(suppliers).ThenForEach(x => x.Product.SupplierID = x.SupplierID).ThenBulkMerge(x => x.Product);
}

Try it online

 

Example - Merge with relation (One to Many)

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

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

using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServerW3Schools()))
{
	connection.BulkMerge(suppliers).ThenForEach(x => x.Products.ForEach(y => y.SupplierID =  x.SupplierID)).ThenBulkMerge(x => x.Products);
}

Try it online

你可能感兴趣的:(database)