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
Implements
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 |
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
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 |
|
| Byte | precision | The precision of the mapped database type. |
| Byte | scale | The scale of the mapped database type. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
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 |
|
| Int32 | size | The size of the mapped database type. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
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 |
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
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 |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException |
|
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. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
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. |
| Byte | precision | The precision of the mapped database type. |
| Byte | scale | The scale of the mapped database type. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
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. |
| Int32 | size | The size of the mapped database type. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
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 |
|
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 |
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
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 |
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
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 |
| Type | dotNetType | The .NET CLR type ( |
| AdbColumnSchema | adbColumnSchema | The schema for the database column, or null if not available. |
| ParameterDirection | direction | The parameter direction. |
Returns
| Type | Description |
|---|---|
| Boolean |
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
| ArgumentNullException |
|
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 |
| Type | dotNetType | The .NET CLR type ( |
| 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 |
Returns
| Type | Description |
|---|---|
| Boolean |
|
Exceptions
| Type | Condition |
|---|---|
| ArgumentException |
|
| ArgumentNullException |
|
ToString()
Returns a String that represents this instance.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| String |