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:
- Assign script types with SetScriptType(ScriptTypeProvider?) rather than setting ScriptTypeProvider directly — it also wires the provider's context properties (culture, source and destination column, mapping and job) onto the provider.
- When a ScriptTypeProvider is set, ConvertInputValueToOutputValue(object) returns the provider's value as-is and skips the standard type conversion, so the provider must return a value compatible with the destination column type.
- Type conversion is culture-sensitive: it uses FormatCulture when set, otherwise the culture of the job (see GetEffectiveCulture() and GetCulture()). Conversion failures throw InvalidCastException, which fails the row during job execution.
- SourceColumn and DestinationColumn can be
null— for example when the mapping uses a script type that needs no source (DisableSource) or when the job file references columns that no longer exist in the schema (see OriginalSourceColumnName and OriginalDestinationColumnName).
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
sourceColumnColumnThe column the value is read from, or
nullwhen the mapping has no source column.destinationColumnColumnThe column the value is written to, or
nullwhen unresolved.idintThe id of the column mapping; also used as the initial Sort value.
iskeyboolIf 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
sourceColumnColumnThe column the value is read from, or
nullwhen the mapping has no source column.destinationColumnColumnThe column the value is written to, or
nullwhen unresolved.idintThe id of the column mapping; also used as the initial Sort value.
iskeyboolIf set to
true, the mapping is used as a key when matching destination rows.useCodeExtensionboolSets 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
xmlNodeXmlNodeThe
columnMappingXML node. Child nodes with unknown names cause an exception.sourceISourceThe source of the job the mapping belongs to.
destinationIDestinationThe destination of the job the mapping belongs to.
sourceTableTableThe table the source column is resolved against, or
nullwhen the table no longer exists.destinationTableTableThe table the destination column is resolved against, or
nullwhen the table no longer exists.idintThe 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
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
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
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
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
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
trueif 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
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
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
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
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
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
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
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
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
inputObjectobjectThe 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
inputObjectobjectThe value read from the source column for the current row.
sourceColumnColumnThe column the value was read from; its type guides the parsing.
destinationColumnColumnThe column whose type the value is converted to.
cultureCultureInfoThe culture used for parsing and conversion, typically GetCulture() of the mapping.
Returns
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
nullwhen no ScriptTypeProvider is set or the provider requires a source value (DisableSource isfalse).
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
scriptTypeScriptTypeProviderThe provider to assign, or
nullto remove scripting from the mapping.