Search Results for

    Show / Hide Table of Contents

    Class AdbTypeMapper

    Stores mappings between .NET types and database types, and allows setting the database type of database parameters from these mappings. Many mappings to provider-independent DbType database types are common across database providers, while other mappings are specific to each provider.

    To create a new type mapper, inherit from this class and set mappings in the constructor.

    When the database type is known at compile time, the user or worker should set it explicitly. The mappings are instead used when the database type is only known at runtime, by automatically setting it with SetMappedType(AdbParameter, Type, AdbColumnSchema, ParameterDirection).

    Note that the .NET type name is specified as the compact display name returned by DisplayName(Type).

    Also see predefined type mappings.

    This class is immutable. This avoids threading issues, since an instance is often accessed by multiple threads. Any user custom provider services should also be immutable for the same reason.

    Inheritance
    Object
    AdbTypeMapper
    AdbMySqlClientTypeMapper
    AdbMySqlConnectorTypeMapper
    AdbNpgsqlTypeMapper
    AdbOdbcTypeMapper
    AdbSqlClientTypeMapper
    AdbSQLiteTypeMapper
    Implements
    IAdbTypeMapper
    Namespace: actionETL.Adb
    Assembly: actionETL.dll
    Syntax
    public class AdbTypeMapper : IAdbTypeMapper

    Constructors

    AdbTypeMapper()

    Initializes a new instance of the AdbTypeMapper class, which stores mappings between .NET types and database types, and allows setting the database type of database parameters from these mappings.

    Declaration
    protected AdbTypeMapper()

    Fields

    SetMappedTypeEnumMySqlTypePrefixes

    Prefix strings where one must match DataTypeName for an on-the-fly enum to integer mapping to be made.

    Declaration
    protected static readonly string[] SetMappedTypeEnumMySqlTypePrefixes
    Field Value
    Type Description
    String[]

    SetMappedTypeEnumSqlClientTypePrefixes

    Prefix strings where one must match DataTypeName for an on-the-fly enum to integer mapping to be made.

    Declaration
    protected static readonly string[] SetMappedTypeEnumSqlClientTypePrefixes
    Field Value
    Type Description
    String[]

    Methods

    AddOrUpdateDbType(String, DbType)

    Adds or updates a provider-independent DbType database type mapping.

    Declaration
    protected void AddOrUpdateDbType(string dotNetTypeName, DbType dbType)
    Parameters
    Type Name Description
    String dotNetTypeName

    Name of the .NET CLR type, e.g. "System.Int32". Must not be empty.

    DbType dbType

    DbType enumeration value to map to.

    Exceptions
    Type Condition
    ArgumentException
    • dbType - Not a valid DbType.
    • dotNetTypeName - Must supply a non-empty value.

    AddOrUpdateDbType(String, DbType, Byte, Byte)

    Adds or updates a provider-independent DbType database type mapping.

    Declaration
    protected void AddOrUpdateDbType(string dotNetTypeName, DbType dbType, byte precision, byte scale)
    Parameters
    Type Name Description
    String dotNetTypeName

    Name of the .NET CLR type, e.g. "System.Int32". Must not be empty.

    DbType dbType

    DbType enumeration value to map to.

    Byte precision

    The precision of the mapped database type.

    Byte scale

    The scale of the mapped database type.

    Exceptions
    Type Condition
    ArgumentException
    • dbType - Not a valid DbType.
    • dotNetTypeName - Must supply a non-empty value.

    AddOrUpdateDbType(String, DbType, Int32)

    Adds or updates a provider-independent DbType database type mapping.

    Declaration
    protected void AddOrUpdateDbType(string dotNetTypeName, DbType dbType, int size)
    Parameters
    Type Name Description
    String dotNetTypeName

    Name of the .NET CLR type, e.g. "System.Int32". Must not be empty.

    DbType dbType

    DbType enumeration value to map to.

    Int32 size

    The size of the mapped database type.

    Exceptions
    Type Condition
    ArgumentException
    • dbType - Not a valid DbType.
    • dotNetTypeName - Must supply a non-empty value.

    AddOrUpdateDbTypeWithNullable(String, DbType)

    Adds or updates a mapping from both the specified .Net type (e.g. "System.Int32") and a nullable version of the same type (i.e. "System.Int32?") to a provider-independent DbType database type (e.g. DbType.Int32).

    Note that this is just a helper method, a nullable type mapping can be added on its own by using another method.

    Declaration
    protected void AddOrUpdateDbTypeWithNullable(string dotNetTypeName, DbType dbType)
    Parameters
    Type Name Description
    String dotNetTypeName

    Name of the .NET CLR type, e.g. "System.Int32". Must not be empty.

    DbType dbType

    DbType enumeration value to map to.

    Exceptions
    Type Condition
    ArgumentException
    • dbType - Not a valid DbType.
    • dotNetTypeName - Must supply a non-empty value.

    AddOrUpdateFunc(String, Func<AdbParameter, Type, AdbColumnSchema, ParameterDirection, Boolean>)

    Adds or updates a database type mapping function, that will be called every time a mapping is needed. Note that workers normally use this once, not per row.

    Declaration
    protected void AddOrUpdateFunc(string dotNetTypeName, Func<AdbParameter, Type, AdbColumnSchema, ParameterDirection, bool> setParameterTypeFunc)
    Parameters
    Type Name Description
    String dotNetTypeName

    Name of the .NET CLR type, e.g. "System.Int32". Must not be empty.

    Func<AdbParameter, Type, AdbColumnSchema, ParameterDirection, Boolean> setParameterTypeFunc

    The parameter type mapping function. It must return true if the mapped type is a provider-specific type, false if the mapped type is a DbType, and null if no mapping was found.

    Exceptions
    Type Condition
    ArgumentNullException

    setParameterTypeFunc

    ArgumentException

    dotNetTypeName - Must supply a non-empty value.

    AddOrUpdateProviderType(String, Object)

    Adds or updates a provider-specific database type mapping.

    Declaration
    protected void AddOrUpdateProviderType(string dotNetTypeName, object providerTypeEnum)
    Parameters
    Type Name Description
    String dotNetTypeName

    Name of the .NET CLR type, e.g. "System.Int32". Must not be empty.

    Object providerTypeEnum

    Provider-specific enumeration value to map to, e.g. SqlDbType.UniqueIdentifier.

    Exceptions
    Type Condition
    ArgumentException

    dotNetTypeName - Must supply a non-empty value.

    AddOrUpdateProviderType(String, Object, Byte, Byte)

    Adds or updates a provider-specific database type mapping.

    Declaration
    protected void AddOrUpdateProviderType(string dotNetTypeName, object providerTypeEnum, byte precision, byte scale)
    Parameters
    Type Name Description
    String dotNetTypeName

    Name of the .NET CLR type, e.g. "System.Int32". Must not be empty.

    Object providerTypeEnum

    Provider-specific enumeration value to map to, e.g. SqlDbType.UniqueIdentifier.

    Byte precision

    The precision of the mapped database type.

    Byte scale

    The scale of the mapped database type.

    Exceptions
    Type Condition
    ArgumentException

    dotNetTypeName - Must supply a non-empty value.

    AddOrUpdateProviderType(String, Object, Int32)

    Adds or updates a provider-specific database type mapping.

    Declaration
    protected void AddOrUpdateProviderType(string dotNetTypeName, object providerTypeEnum, int size)
    Parameters
    Type Name Description
    String dotNetTypeName

    Name of the .NET CLR type, e.g. "System.Int32". Must not be empty.

    Object providerTypeEnum

    Provider-specific enumeration value to map to, e.g. SqlDbType.UniqueIdentifier.

    Int32 size

    The size of the mapped database type.

    Exceptions
    Type Condition
    ArgumentException

    dotNetTypeName - Must supply a non-empty value.

    AddOrUpdateUntyped(String)

    Adds or updates a mapping to untyped, i.e. to not set a type but still report a mapping was found. The database provider will deduce the database type at runtime for each value, e.g. for each row.

    Note that allowing the provider to deduce the type is both error prone and can result in lower performance, so it is recommended to only use mappings that set the type explicitly, or use a Runtime mapping (which has access to more information than the provider), if at all possible.

    Declaration
    protected void AddOrUpdateUntyped(string dotNetTypeName)
    Parameters
    Type Name Description
    String dotNetTypeName

    Name of the .NET CLR type, e.g. "System.Int32". Must not be empty.

    Exceptions
    Type Condition
    ArgumentException

    dotNetTypeName - Must supply a non-empty value.

    IsMapped(String)

    Determines whether the specified .NET CLR type name is mapped.

    Declaration
    protected bool IsMapped(string dotNetTypeName)
    Parameters
    Type Name Description
    String dotNetTypeName

    Name of the .NET CLR type, e.g. "System.Int32". Must not be empty.

    Returns
    Type Description
    Boolean

    true if the specified .NET CLR type name is mapped; otherwise, false.

    Exceptions
    Type Condition
    ArgumentException

    dotNetTypeName - Must supply a non-empty value.

    Remove(String)

    Removes the specified .NET CLR type mapping.

    Declaration
    protected bool Remove(string dotNetTypeName)
    Parameters
    Type Name Description
    String dotNetTypeName

    Name of the .NET CLR type, e.g. "System.Int32". Must not be empty.

    Returns
    Type Description
    Boolean

    true if the mapping was found and removed, otherwise false.

    Exceptions
    Type Condition
    ArgumentException

    dotNetTypeName - Must supply a non-empty value.

    SetMappedType(AdbParameter, Type, AdbColumnSchema, ParameterDirection)

    Set the database type of a database parameter, using previously defined mappings. Override and call this method to add type processing before or after this type lookup is performed.

    The database type can be provider-independent such as System.Data.DbType Int32, or a provider-specific one such as System.Data.SqlDbType UniqueIdentifier, or Untyped, which means the provider deduces the database type for each value, e.g. for each row.

    Declaration
    public virtual bool SetMappedType(AdbParameter adbParameter, Type dotNetType, AdbColumnSchema adbColumnSchema, ParameterDirection direction)
    Parameters
    Type Name Description
    AdbParameter adbParameter

    The database parameter. Must not be null.

    Type dotNetType

    The .NET CLR type (string, SqlDateTime, etc.) Must not be null.

    AdbColumnSchema adbColumnSchema

    The schema for the database column, or null if not available.

    ParameterDirection direction

    The parameter direction.

    Returns
    Type Description
    Boolean

    true if a mapping was found (including Untyped), otherwise false.

    Exceptions
    Type Condition
    ArgumentException
    • providerTypeEnum is not of the correct provider type.
    • The property is not set to a valid DbType.
    ArgumentNullException
    • adbColumnSchema
    • adbParameter
    • dotNetType

    SetMappedTypeForEnum(AdbParameter, Type, AdbColumnSchema, ParameterDirection, IEnumerable<String>)

    Internal method to set the database type of a database parameter, using previously defined mappings.

    The database type can be provider-independent such as System.Data.DbType Int32, or a provider-specific one such as System.Data.SqlDbType UniqueIdentifier, or Untyped, which means the provider deduces the database type for each value, e.g. for each row.

    If no pre-defined mapping is found, and dotNetType is an enum or nullable enum, and adbColumnSchema is either null or an integral type, then the parameter is mapped to the enum underlying type. This allows the enum to be stored in an integer column.

    Declaration
    protected bool SetMappedTypeForEnum(AdbParameter adbParameter, Type dotNetType, AdbColumnSchema adbColumnSchema, ParameterDirection direction, IEnumerable<string> sqlTypePrefixes)
    Parameters
    Type Name Description
    AdbParameter adbParameter

    The database parameter. Must not be null.

    Type dotNetType

    The .NET CLR type (string, SqlDateTime, etc.) Must not be null.

    AdbColumnSchema adbColumnSchema

    The schema for the database column, or null if not available.

    ParameterDirection direction

    The parameter direction.

    IEnumerable<String> sqlTypePrefixes

    An on-the-fly mapping from an enum to an integer is only attempted if either adbColumnSchema.DataTypeName has no value, or it has a value and one of the sqlTypePrefixes string matches the start of adbColumnSchema.DataTypeName.

    Returns
    Type Description
    Boolean

    true if a mapping was found (including Untyped), otherwise false.

    Exceptions
    Type Condition
    ArgumentException
    • providerTypeEnum is not of the correct provider type.
    • The property is not set to a valid DbType.
    ArgumentNullException
    • adbColumnSchema
    • adbParameter
    • dotNetType

    ToString()

    Returns a String that represents this instance.

    Declaration
    public override string ToString()
    Returns
    Type Description
    String
    Overrides
    Object.ToString()

    Implements

    IAdbTypeMapper

    See Also

    IAdbTypeMapper
    In This Article
    Back to top Copyright © 2023 Envobi Ltd