Entity Framework Extensions Column PrimaryKey Expression

The ColumnPrimaryKeyExpression allows you to choose a specific property or properties as a key to perform the bulk operations.

The following example uses Login and Password properties as a key to perform BulkMerge.

using (var context = new EntityContext())
{
    context.BulkMerge(list, 
        options => options.ColumnPrimaryKeyExpression = customer => new 
        { 
            customer.Login, 
            customer.Password 
        }
    );
}

Try it in EF6 | Try it in EF Core

It will update those records for which the Login and Password already exist in the database and all the new records will be inserted to the database.


Related