30% OFF - 10th Anniversary discount on new purchases until December 15 with code: ZZZANNIVERSARY10
Entity Framework Extensions Ignore OnInsert Expression
Description
The IgnoreOnInsertExpression
allows you to ignore some columns when the BulkInsert
method is executed.
The following example ignores the ModifiedDate
property when bulk insert operation is performed.
using (var context = new EntityContext()) { var customers = new List<Customer>(); customers.Add(new Customer() { Name = "Alexander", Description = "Description of Alexander", CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsActive = true }); customers.Add(new Customer() { Name = "Carson", Description = "Description of Carson", CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsActive = true }); customers.Add(new Customer() { Name = "Meredith", Description = "Description of Meredith", CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsActive = true }); customers.Add(new Customer() { Name = "Arturo", Description = "Description of Arturo", CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now, IsActive = true }); context.BulkInsert(customers, options => { options.IgnoreOnInsertExpression = customer => new {customer.CustomerID, customer.ModifiedDate}; }); }
- It will insert data in all the columns except for the
ModifiedDate
column becauseModifiedDate
property is specified inIgnoreOnInsertExpression
.
ZZZ Projects