Search Results for

    Show / Hide Table of Contents

    Class FromTypeColumnMapper<TFrom>

    Defines mappings from the (potentially hierarchical) fields, properties, table columns etc. of a source 'from' .NET CLR type (described by FromRowSchema), to a flat list of user supplied or automatically generated target 'to' columns (described by ToRowSchema).

    This facility is commonly used by dataflow workers for copying and renaming column data between input fields and properties on the one hand, and external data sources on the other hand.

    Members to be mapped can be specified explicitly via name or index (e.g. copy from input column "A" to the fourth output column), as well as implicitly based on name (i.e. AutoName()). A specified field or property on the 'from' side can reside inside a column schema, i.e. a struct that groups multiple fields and properties.

    This class does not include the Row() method, and should be used when the Row() method is not supported by the worker in question. Also see IRowMapperCommand which does include that method.

    Mappings can be specified with the columnMapperCommandAction parameter, or added by calling the mapping methods Name(String) etc. The mapping result is available in Mappings, which the caller can use to manually perform any tasks, such as copy columns.

    Also see the Dataflow Column Mapping and Mapping and Copying examples, as well as IRowMapperCommand and IColumnMapperCommand.

    Note: If the mapping commands result in duplicate mappings, an exception will be thrown. Resolve this by either of:

    • Specify additional or all name parts in explicit mapping
    • Change the column (or schema) names in the from and/or to rows to avoid name clashes
    • Restrict auto-mapping to specific column schemas
    • Map offending columns explicitly by name (which will exclude them from later auto-mappings)

    Inheritance
    Object
    FromTypeColumnMapper<TFrom>
    Implements
    IColumnMapperCommand
    IFluentInterface
    Namespace: actionETL
    Assembly: actionETL.dll
    Syntax
    public class FromTypeColumnMapper<TFrom> : IColumnMapperCommand, IFluentInterface
    Type Parameters
    Name Description
    TFrom

    The source 'from' type.

    Constructors

    FromTypeColumnMapper(Action<IColumnMapperCommand>)

    Initializes a new instance of the FromTypeColumnMapper<TFrom> class, which defines mappings between the fields, properties, table columns etc. of a source 'from' .NET CLR type, to a set of target 'to' column names, automatically created from all source 'from' column names.

    Column name matching is ordinal case insensitive, but a case sensitive match takes precedence over a case insensitive match.

    Also see the Dataflow Column Mapping and Mapping and Copying examples, as well as IRowMapperCommand and IColumnMapperCommand.

    Declaration
    public FromTypeColumnMapper(Action<IColumnMapperCommand> columnMapperCommandAction)
    Parameters
    Type Name Description
    Action<IColumnMapperCommand> columnMapperCommandAction

    An action that executes commands that define the column mappings, e.g. mapping two columns using from-name and to-index:

    cbc => cbc.Name("ColumnA", "0").Name("ColumnB", "1")

    Set to null to not add any initial mappings.

    FromTypeColumnMapper(IEnumerable<String>, Action<IColumnMapperCommand>)

    Initializes a new instance of the FromTypeColumnMapper<TFrom> class, which defines mappings between the fields, properties, table columns etc. of a source 'from' .NET CLR type, to a set of user supplied target 'to' columns.

    Column name matching is ordinal case insensitive, but a case sensitive match takes precedence over a case insensitive match.

    Also see the Dataflow Column Mapping and Mapping and Copying examples, as well as IRowMapperCommand and IColumnMapperCommand.

    Declaration
    public FromTypeColumnMapper(IEnumerable<string> toColumnNames, Action<IColumnMapperCommand> columnMapperCommandAction)
    Parameters
    Type Name Description
    IEnumerable<String> toColumnNames

    Target 'to' column names.

    Action<IColumnMapperCommand> columnMapperCommandAction

    An action that executes commands that define the column mappings, e.g. mapping two columns by name:

    cbc => cbc.Name("ColumnWithSameName").Name("FromColumn", "ToColumn")

    Set to null to not add any initial mappings.

    Properties

    Mappings

    Gets the mapper result. It provides the mappings as well as type and other information about the 'from' and 'to' sides.

    Declaration
    public FromTypeColumnMappings Mappings { get; }
    Property Value
    Type Description
    FromTypeColumnMappings

    Methods

    AutoName()

    Map automatically by name. Identical names will match, as will partial names where one or more of the left-most parts of the name have been left out. E.g., "Person.Name.FirstName" would automatically map to either of "FirstName" and "Name.FirstName". More matching parts take precedence over fewer matching parts.

    Column name matching is ordinal case insensitive, but a case sensitive match takes precedence over a case insensitive match.

    The mapping only considers readable (see CanRead) 'from' columns.

    Note: If there are still more than one possible mapping, an exception will be thrown. Resolve this by either of:

    • Change the column names in the row(s) to avoid name clashes
    • Use one of the overloads that allows restricting the auto-mapping to specific hierarchy names
    • Map offending columns individually by name (which will exclude them from later mappings), before calling this auto-mapping method

    Declaration
    public IColumnMapperCommand AutoName()
    Returns
    Type Description
    IColumnMapperCommand

    The IColumnMapperCommand instance itself, which allows chaining commands.

    Exceptions
    Type Condition
    InvalidOperationException
    • Duplicate matches.

    AutoName(Int32)

    Map automatically by name. Identical names will match, as will partial names where one or more of the left-most parts of the name have been left out. E.g., "Person.Name.FirstName" would automatically map to either of "FirstName" and "Name.FirstName". More matching parts take precedence over fewer matching parts.

    Column name matching is ordinal case insensitive, but a case sensitive match takes precedence over a case insensitive match.

    The mapping only considers readable (see CanRead) 'from' columns.

    Note: If there are still more than one possible mapping, an exception will be thrown. Resolve this by either of:

    • Change the column names in the row(s) to avoid name clashes
    • Use one of the overloads that allows restricting the auto-mapping to specific hierarchy names
    • Map offending columns individually by name (which will exclude them from later mappings), before calling this auto-mapping method

    Declaration
    public IColumnMapperCommand AutoName(int assertNumberOfMatches)
    Parameters
    Type Name Description
    Int32 assertNumberOfMatches

    Assert number of matches.

    Returns
    Type Description
    IColumnMapperCommand

    The IColumnMapperCommand instance itself, which allows chaining commands.

    Exceptions
    Type Condition
    InvalidOperationException
    • Duplicate matches.

    AutoName(Int32, String, String)

    Map automatically by name. Identical names will match, as will partial names where one or more of the left-most parts of the name have been left out. E.g., "Person.Name.FirstName" would automatically map to either of "FirstName" and "Name.FirstName". More matching parts take precedence over fewer matching parts.

    Column name matching is ordinal case insensitive, but a case sensitive match takes precedence over a case insensitive match.

    The mapping only considers readable (see CanRead) 'from' columns.

    Note: If there are still more than one possible mapping, an exception will be thrown. Resolve this by either of:

    • Change the column names in the row(s) to avoid name clashes
    • Restrict the auto-mapping to specific hierarchy names
    • Map offending columns individually by name (which will exclude them from later mappings), before calling this auto-mapping method

    Declaration
    public IColumnMapperCommand AutoName(int assertNumberOfMatches, string fromHierarchyName, string toHierarchyName)
    Parameters
    Type Name Description
    Int32 assertNumberOfMatches

    Assert number of matches.

    String fromHierarchyName

    Hierarchy from name to include, or null to include all members. Name parts can be omitted from the right, e.g. specifying "Person" will only auto-map from the "Person" member residing directly in the root of the row class, and any descendants of "Person".

    String toHierarchyName

    Hierarchy to name to include, or null to include all members. Name parts can be omitted from the right, e.g. specifying "Person" will only auto-map to the "Person" member residing directly in the root of the row class, and any descendants of "Person".

    Returns
    Type Description
    IColumnMapperCommand

    The IColumnMapperCommand instance itself, which allows chaining commands.

    Exceptions
    Type Condition
    InvalidOperationException
    • Duplicate matches.

    AutoName(String, String)

    Map automatically by name. Identical names will match, as will partial names where one or more of the left-most parts of the name have been left out. E.g., "Person.Name.FirstName" would automatically map to either of "FirstName" and "Name.FirstName". More matching parts take precedence over fewer matching parts.

    Column name matching is ordinal case insensitive, but a case sensitive match takes precedence over a case insensitive match.

    The mapping only considers readable (see CanRead) 'from' columns.

    Note: If there are still more than one possible mapping, an exception will be thrown. Resolve this by either of:

    • Change the column names in the row(s) to avoid name clashes
    • Restrict the auto-mapping to specific hierarchy names
    • Map offending columns individually by name (which will exclude them from later mappings), before calling this auto-mapping method

    Declaration
    public IColumnMapperCommand AutoName(string fromHierarchyName, string toHierarchyName)
    Parameters
    Type Name Description
    String fromHierarchyName

    Hierarchy from name to include, or null to include all members. Name parts can be omitted from the right, e.g. specifying "Person" will only auto-map from the "Person" member residing directly in the root of the row class, and any descendants of "Person".

    String toHierarchyName

    Hierarchy to name to include, or null to include all members. Name parts can be omitted from the right, e.g. specifying "Person" will only auto-map to the "Person" member residing directly in the root of the row class, and any descendants of "Person".

    Returns
    Type Description
    IColumnMapperCommand

    The IColumnMapperCommand instance itself, which allows chaining commands.

    Exceptions
    Type Condition
    InvalidOperationException
    • Duplicate matches.

    Index(Int32, Int32)

    Map a 'from' column to a 'to' column based on their index in SchemaNodeList.

    Declaration
    public IColumnMapperCommand Index(int fromSchemaNodeListIndex, int toSchemaNodeListIndex)
    Parameters
    Type Name Description
    Int32 fromSchemaNodeListIndex

    From index.

    Int32 toSchemaNodeListIndex

    To index.

    Returns
    Type Description
    IColumnMapperCommand

    The IColumnMapperCommand instance itself, which allows chaining commands.

    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    schemaNodeListIndex was outside [0, number of items).

    InvalidOperationException
    • Column already mapped
    • Duplicate column mappings

    Name(String)

    Map a 'from' column to a 'to' column based on their names.

    Column name matching is ordinal case insensitive, but a case sensitive match takes precedence over a case insensitive match.

    Declaration
    public IColumnMapperCommand Name(string schemaNodeName)
    Parameters
    Type Name Description
    String schemaNodeName

    Name of both the 'from' and 'to' columns. Column schema names can optionally be omitted from the left, as long as the specified name is unique among all columns in the row. E.g., assuming "FirstName" is unique, the following can all identify the same column:

    • "Person.Name.FirstName"
    • "Name.FirstName"
    • "FirstName"

    Returns
    Type Description
    IColumnMapperCommand

    The IColumnMapperCommand instance itself, which allows chaining commands.

    Exceptions
    Type Condition
    InvalidOperationException
    • Member not found
    • Found more than one member match in type
    • Name already mapped
    ArgumentNullException

    schemaNodeName

    Name(String, String)

    Map a 'from' column to a 'to' column based on their names.

    Column name matching is ordinal case insensitive, but a case sensitive match takes precedence over a case insensitive match.

    Declaration
    public IColumnMapperCommand Name(string fromSchemaNodeName, string toSchemaNodeName)
    Parameters
    Type Name Description
    String fromSchemaNodeName

    Name of the 'from' column. Column schema names can optionally be omitted from the left, as long as the specified name is unique among all columns in the row. E.g., assuming "FirstName" is unique, the following can all identify the same column:

    • "Person.Name.FirstName"
    • "Name.FirstName"
    • "FirstName"

    String toSchemaNodeName

    Name of the 'to' column. Column schema names can optionally be omitted from the left, as long as the specified name is unique among all columns in the row. E.g., assuming "FirstName" is unique, the following can all identify the same column:

    • "Person.Name.FirstName"
    • "Name.FirstName"
    • "FirstName"

    Returns
    Type Description
    IColumnMapperCommand

    The IColumnMapperCommand instance itself, which allows chaining commands.

    Exceptions
    Type Condition
    InvalidOperationException
    • Member not found
    • Found more than one member match in type
    • Name already mapped
    ArgumentNullException
    • fromSchemaNodeName
    • toSchemaNodeName

    Implements

    IColumnMapperCommand
    IFluentInterface

    See Also

    IColumnMapperCommand
    FromTypeRowMapper<TFrom>
    TypeRowMapper<TFrom, TTo>
    ToTypeRowMapper<TTo>
    TypeColumnCopier<TFrom, TTo>
    In This Article
    Back to top Copyright © 2021 Envobi Ltd