Entity Framework Extensions Column Input Expression

Description

The ColumnInputExpression allows you to choose specific properties of an entity in which you want to perform the bulk operations.

The following example inserts data to the database by specifying Name and IsActive properties using the BulkInsert operation.

using (var context = new EntityContext())
{
    context.BulkInsert(list, 
        options => options.ColumnInputExpression = c => new 
        { 
            c.Name, 
            c.IsActive 
        }
    );
}

Try it: EF Core | EF6

The key is required for operation such as BulkUpdate and BulkMerge.

using (var context = new EntityContext())
{
    List<Customer> list = context.Customers.ToList();
    list.Add(new Customer() { Name ="Customer_C", Description = "Description", IsActive = true });
            
    context.BulkMerge(list, options => 
        options.ColumnInputExpression = c => new 
        {
            c.CustomerID, 
            c.Name, 
            c.IsActive 
        }
    );
}

Try it: EF Core | EF6

  • It will insert data to Name and IsActive columns as specified in ColumnInputExpression.
  • The data in Description property is ignored during bulk operation.

Last updated: 2023-03-01
Author:


Contents