EDBBulkColumnMappingsBehavior
An enumeration that is being used to define how a bulk operation aligns the columns of the source with the columns of the destination table.
This enum defines how a bulk operation (BulkInsert, BulkMerge, BulkUpdate and BulkDelete) aligns the columns of the source (entities, DataTable or DbDataReader) with the columns of the destination table, when no explicit mappings argument was passed to the operation — an explicit mappings argument always takes precedence over this setting. It applies only to EnterpriseDB.
Enum Values
| Name | Description |
|---|---|
| Automatic | Only the columns that exist on both the source and the destination table (matched by name) are mapped; all other columns are ignored on either side, and column order does not matter. This is the default value, and preserves the library’s pre-existing behavior. |
| Strict | The columns of the source must be identical to the columns of the destination table in both name and order. Any difference — a missing column on either side, or a different order — throws an EDBBulkColumnMappingsException before any data is written. |
| StrictBypass | Every column of the source must exist on the destination table (matched by name), but column order does not matter. Destination columns not supplied by the source are bypassed (left to their default, identity or computed values). A source column that does not exist on the destination table throws an EDBBulkColumnMappingsException before any data is written, so no source data is ever silently dropped. |
Usability
Set this via the EDBBulkOperationsDbSetting class and register it through EnterpriseDbGlobalConfiguration — the behavior then applies to every bulk operation call on EDBConnection that passes no explicit mappings.
GlobalConfiguration
.Setup()
.UseEnterpriseDb(new EDBBulkOperationsDbSetting
{
BulkColumnMappingsBehavior = EDBBulkColumnMappingsBehavior.Strict
});
For example, with a Customer table that has the Id, Name, Email, and CreatedDateUtc columns, and a list of entities (the source) with the Email, Name, and Nickname properties:
Strictthrows, because the order differs,Id/CreatedDateUtcare missing, andNicknamedoes not exist in the destination.StrictBypassthrows, becauseNicknamedoes not exist in the destination.AutomaticinsertsNameandEmail, and ignoresNickname.
StrictandStrictBypassboth throw anEDBBulkColumnMappingsException(naming every offending column) before any data is written, so no source data is ever silently dropped due to a typo’d or missing column name.