Table of Contents

Class ColumnMapping

Namespace
Dynamicweb.DataIntegration.Integration
Assembly
Dynamicweb.DataIntegration.dll

Maps a single source column to a single destination column within a table Mapping, and defines how the value is transformed on the way: optional scripting through a ScriptTypeProvider, culture-aware type conversion, null/empty handling and whether the mapping participates as a key when matching existing destination rows. Destination writers call ConvertInputValueToOutputValue(object) for every row to obtain the value to write.

public class ColumnMapping
Inheritance
ColumnMapping
Inherited Members
Extension Methods

Remarks

Column mappings are owned by a table Mapping. Create them through AddMapping(Column?, Column?) (or AddResponseMapping(Column?, Column, bool) for response mappings) when building a job in code; when a saved job is loaded, they are deserialized from the job XML file. Retrieve them with GetColumnMappings(), which returns only active mappings that have a destination column, ordered by Sort.

Things to be careful of:

Typical use from a provider's destination writer, converting a source row value before writing it:
foreach (ColumnMapping columnMapping in mapping.GetColumnMappings())
{
    // Script types like Constant produce a value without a source column
    bool scripted = columnMapping.ScriptTypeProvider?.DisableSource ?? false;
    object? rowValue = null;
    if (!scripted && (columnMapping.SourceColumn is null || !row.TryGetValue(columnMapping.SourceColumn.Name, out rowValue)))
        continue;

    object? outputValue = columnMapping.ConvertInputValueToOutputValue(rowValue ?? DBNull.Value);
    // write outputValue to the destination under columnMapping.DestinationColumn.Name
}

Constructors

ColumnMapping()

Initializes a new active instance of the ColumnMapping class without columns or id. Intended for derived classes that populate the mapping themselves.

protected ColumnMapping()

ColumnMapping(Column?, Column?, int, bool)

Initializes a new active instance of the ColumnMapping class. Prefer creating mappings through AddMapping(Column?, Column?), which assigns the id and sets the owning mapping.

public ColumnMapping(Column? sourceColumn, Column? destinationColumn, int id, bool iskey = false)

Parameters

sourceColumn Column

The column the value is read from, or null when the mapping has no source column.

destinationColumn Column

The column the value is written to, or null when unresolved.

id int

The id of the column mapping; also used as the initial Sort value.

iskey bool

If set to true, the mapping is used as a key when matching destination rows.

ColumnMapping(Column?, Column?, int, bool, bool)

Initializes a new active instance of the ColumnMapping class with the legacy code extension flag. Prefer creating mappings through AddMapping(Column?, Column?), which assigns the id and sets the owning mapping.

public ColumnMapping(Column? sourceColumn, Column? destinationColumn, int id, bool iskey, bool useCodeExtension)

Parameters

sourceColumn Column

The column the value is read from, or null when the mapping has no source column.

destinationColumn Column

The column the value is written to, or null when unresolved.

id int

The id of the column mapping; also used as the initial Sort value.

iskey bool

If set to true, the mapping is used as a key when matching destination rows.

useCodeExtension bool

Sets the obsolete Dynamicweb.DataIntegration.Integration.ColumnMapping.UseCodeExtension flag; only relevant for backwards compatibility with legacy code extension scripts.

ColumnMapping(XmlNode, ISource?, IDestination?, Table?, Table?, int)

Initializes a new instance of the ColumnMapping class from a columnMapping XML node in a saved job file — the format this class itself writes when the job is saved. Called by the framework when a job file is loaded. Columns are resolved by name against the given tables; names that cannot be resolved are kept in OriginalSourceColumnName and OriginalDestinationColumnName. Script types are re-created through the add-in system and wired up via SetScriptType(ScriptTypeProvider?).

public ColumnMapping(XmlNode xmlNode, ISource? source, IDestination? destination, Table? sourceTable, Table? destinationTable, int id)

Parameters

xmlNode XmlNode

The columnMapping XML node. Child nodes with unknown names cause an exception.

source ISource

The source of the job the mapping belongs to.

destination IDestination

The destination of the job the mapping belongs to.

sourceTable Table

The table the source column is resolved against, or null when the table no longer exists.

destinationTable Table

The table the destination column is resolved against, or null when the table no longer exists.

id int

The id of the column mapping; also used as the Sort value unless the XML specifies one.

Fields

ScriptValueForInsert

When true, the scripted value is only written when inserting new destination rows; writers exclude the column from updates of existing rows. The default is false (the value is written on both insert and update).

public bool ScriptValueForInsert

Field Value

bool

Properties

Active

Gets or sets a value indicating whether this column mapping participates in job execution. Inactive mappings are excluded from GetColumnMappings() and are not written to the destination. The non-XML constructors default this to true; the XML constructor sets it from the saved isActive node instead.

public virtual bool Active { get; set; }

Property Value

bool

Comment

Gets or sets a free-text note about the column mapping, shown in the data integration job editor and persisted with the job file. Has no effect on job execution.

public string? Comment { get; set; }

Property Value

string

DestinationColumn

Gets or sets the column the converted value is written to in the destination. Mappings without a destination column are excluded from GetColumnMappings(); the column can be unresolved when it no longer exists in the destination schema (see OriginalDestinationColumnName).

public virtual Column? DestinationColumn { get; set; }

Property Value

Column

FormatCulture

Gets or sets the name of the culture used for type conversion of this mapping's values, for example "en-US". When not set, the culture of the job is used (see GetEffectiveCulture() and GetCulture()).

public string? FormatCulture { get; set; }

Property Value

string

IsKey

Gets or sets a value indicating whether this column mapping is used as a key when matching source rows against existing destination rows, determining whether a row is inserted or updated.

public virtual bool IsKey { get; set; }

Property Value

bool

true if this column mapping is a key; otherwise, false.

Mapping

Gets the table mapping that owns this column mapping. Populated by the framework when the column mapping is created through AddMapping(Column?, Column?) or loaded from a job file; null for column mappings constructed directly.

public Mapping? Mapping { get; }

Property Value

Mapping

NullEmptyActionType

Gets or sets how a null or empty source value is handled before the row is written: skip the row, substitute the destination type's default value, or substitute the constant in NullEmptyActionValue. Applied by the framework's row processing during job execution; the default is None (no special handling).

public NullEmptyActionType NullEmptyActionType { get; set; }

Property Value

NullEmptyActionType

NullEmptyActionValue

Gets or sets the constant used instead of a null or empty source value when NullEmptyActionType is Constant. The value is converted to the destination column type using the mapping culture before it is written.

public string? NullEmptyActionValue { get; set; }

Property Value

string

OriginalDestinationColumnName

Gets or sets the destination column name read from the job file when the column could not be resolved against the current destination table schema. Preserved so the name is not lost when the job is saved again; null when DestinationColumn resolved successfully.

public string? OriginalDestinationColumnName { get; set; }

Property Value

string

OriginalSourceColumnName

Gets or sets the source column name read from the job file when the column could not be resolved against the current source table schema. Preserved so the name is not lost when the job is saved again; null when SourceColumn resolved successfully.

public string? OriginalSourceColumnName { get; set; }

Property Value

string

ScriptTypeProvider

Gets or sets the script type provider that transforms the source value for this mapping. When set, ConvertInputValueToOutputValue(object) returns the provider's value instead of applying the standard type conversion. Prefer assigning it through SetScriptType(ScriptTypeProvider?), which also populates the provider's context properties (culture, columns, mapping and job).

public ScriptTypeProvider? ScriptTypeProvider { get; set; }

Property Value

ScriptTypeProvider

Sort

Gets or sets the sort order of the column mapping within its table mapping. GetColumnMappings() returns mappings ordered by this value; it defaults to the mapping id.

public int Sort { get; set; }

Property Value

int

SourceColumn

Gets or sets the column the value is read from in the source row. May be null when the mapping is driven entirely by a script type (see DisableSource) or when the column no longer exists in the source schema (see OriginalSourceColumnName).

public virtual Column? SourceColumn { get; set; }

Property Value

Column

Methods

ConvertInputValueToOutputValue(object)

Produces the value to write to the destination column for a source value. When a ScriptTypeProvider is set, its GetValue(object?) result is returned as-is; otherwise the value is converted to the destination column type using the mapping culture (see GetInputToDestinationTypeOutputFormat(object, Column?, Column?, CultureInfo?)). Called once per row by destination writers during job execution.

public object? ConvertInputValueToOutputValue(object inputObject)

Parameters

inputObject object

The value read from the source column for the current row. Pass Value when there is no source value, for example for script types that need no source.

Returns

object

The value to write to the destination column.

Exceptions

InvalidCastException

No script type is set and the value cannot be converted to the destination column type.

GetCulture()

Gets the culture used for type conversion of this mapping's values: FormatCulture when set, otherwise the culture of the job, which during a run is the one decided when the run started (see GetEffectiveCulture()). An invalid culture name is logged to the job log and the culture of the job is returned.

public CultureInfo GetCulture()

Returns

CultureInfo

The culture to use for parsing and formatting values of this mapping.

GetId()

Gets the id of the column mapping, assigned sequentially by the owning Mapping when the mapping is created or loaded from the job file.

public int GetId()

Returns

int

The id of the column mapping.

GetInputToDestinationTypeOutputFormat(object, Column?, Column?, CultureInfo?)

Converts a source value to the destination column type using the given culture. null, DBNull and the literal string "NULL" convert to Value; values already of the destination type pass through unchanged; DateTime, DateOnly, bool and Guid destinations get dedicated parsing, and all other types are converted with ChangeType(object, Type, IFormatProvider). Date values are clamped to the SQL Server datetime range.

public static object GetInputToDestinationTypeOutputFormat(object inputObject, Column? sourceColumn, Column? destinationColumn, CultureInfo? culture)

Parameters

inputObject object

The value read from the source column for the current row.

sourceColumn Column

The column the value was read from; its type guides the parsing.

destinationColumn Column

The column whose type the value is converted to.

culture CultureInfo

The culture used for parsing and conversion, typically GetCulture() of the mapping.

Returns

object

The value converted to the destination column type, or Value for null-like input.

Exceptions

ArgumentNullException

A column or the culture is null.

InvalidCastException

The value cannot be converted to the destination column type.

GetScriptValue()

Gets the value produced by a source-independent script type such as Constant or NewGuid, as a string.

public string? GetScriptValue()

Returns

string

The provider's value for an empty input, or null when no ScriptTypeProvider is set or the provider requires a source value (DisableSource is false).

SetScriptType(ScriptTypeProvider?)

Assigns a script type provider to the mapping and wires the mapping context onto it: the provider's Culture, SourceColumn, DestinationColumn, Mapping and Job are populated from this mapping. Also keeps the obsolete Dynamicweb.DataIntegration.Integration.ColumnMapping.ScriptType and Dynamicweb.DataIntegration.Integration.ColumnMapping.ScriptValue members in sync for backwards compatibility. Use this instead of setting ScriptTypeProvider directly.

public void SetScriptType(ScriptTypeProvider? scriptType)

Parameters

scriptType ScriptTypeProvider

The provider to assign, or null to remove scripting from the mapping.

To top