Entity Framework Extensions Column Input Expression

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 in EF6 | Try it in EF Core

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 in EF6 | Try it in EF Core

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

Related