Dapper Tutorial Dapper Plus - Unisci massa
Descrizione
MERGE entità utilizzando Bulk Operation.
Esempio: unione singola
MERGE una singola entità con Bulk Operation.
DapperPlusManager.Entity<Customer>().Table("Customers"); using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServerW3Schools())) { connection.BulkMerge(new List<Customer>() { new Customer() { CustomerName = "ExampleBulkMerge", ContactName = "Example Name :" + 1}}); }
include component-try-it.html href = 'https: //dotnetfiddle.net/U6g6Gd'%}
Esempio: Unisci molti
MERGE molte entità con Bulk Operation.
DapperPlusManager.Entity<Customer>().Table("Customers"); using (var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServerW3Schools())) { connection.BulkMerge(customers); }
include component-try-it.html href = 'https: //dotnetfiddle.net/T3R43T'%}
Esempio - Unisci con relazione (Uno a uno)
MERGE entità con una relazione uno a uno con Operazione di massa.
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.BulkMerge(suppliers).ThenForEach(x => x.Product.SupplierID = x.SupplierID).ThenBulkMerge(x => x.Product); }
include component-try-it.html href = 'https: //dotnetfiddle.net/CJfb4l'%}
Esempio - Unisci con relazione (da uno a molti)
MERGE le entità con una relazione uno a molti con l'operazione di massa.
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.BulkMerge(suppliers).ThenForEach(x => x.Products.ForEach(y => y.SupplierID = x.SupplierID)).ThenBulkMerge(x => x.Products); }
include component-try-it.html href = 'https: //dotnetfiddle.net/9C5Yd2'%}