Dapper Plus - Insert en vrac
La description
INSÉRER des entités à l'aide de l'opération en bloc.
- Insérer un seul
- Insérer beaucoup
- Insérer avec relation (One to One)
- Insérer avec relation (Un à plusieurs)
Exemple - Insérer un single
INSCRIRE une seule entité avec l'opération en bloc.
DapperPlusManager.Entity<Customer>().Table("Customers");
using (var connection = new SqlCeConnection("Data Source=SqlCe_W3Schools.sdf"))
{
connection.BulkInsert(new List<Customer>() { new Customer() { CustomerName = "ExampleBulkInsert", ContactName = "Example Name :" + 1}});
}
include composant-try-it.html href = 'https: //dotnetfiddle.net/d8Jxij'%}
Exemple - Insérer plusieurs
INSERT de nombreuses entités avec Bulk Operation.
DapperPlusManager.Entity<Customer>().Table("Customers");
using (var connection = new SqlCeConnection("Data Source=SqlCe_W3Schools.sdf"))
{
connection.BulkInsert(customers);
}
include composant-try-it.html href = 'https: //dotnetfiddle.net/0rXZS9'%}
Exemple - Insérer avec relation (One to One)
INSERT des entités avec une relation un à un avec Bulk Operation.
DapperPlusManager.Entity<Supplier>().Table("Suppliers").Identity(x => x.SupplierID);
DapperPlusManager.Entity<Product>().Table("Products").Identity(x => x.ProductID);
using (var connection = new SqlCeConnection("Data Source=SqlCe_W3Schools.sdf"))
{
connection.BulkInsert(suppliers).ThenForEach(x => x.Product.SupplierID = x.SupplierID).ThenBulkInsert(x => x.Product);
}
include composant-try-it.html href = 'https: //dotnetfiddle.net/9DMDMe'%}
Exemple - Insérer avec relation (Un à plusieurs)
INSÉRER des entités ayant une relation un à plusieurs avec l'opération en bloc.
DapperPlusManager.Entity<Supplier>().Table("Suppliers").Identity(x => x.SupplierID);
DapperPlusManager.Entity<Product>().Table("Products").Identity(x => x.ProductID);
using (var connection = new SqlCeConnection("Data Source=SqlCe_W3Schools.sdf"))
{
connection.BulkInsert(suppliers).ThenForEach(x => x.Products.ForEach(y => y.SupplierID = x.SupplierID)).ThenBulkInsert(x => x.Products);
}
include composant-try-it.html href = 'https: //dotnetfiddle.net/rzZDRy'%}