The DbTypeCheck is a component designed to check the type consistency of all properties of incoming records against their corresponding columns in an existing database table. This ensures that data being processed matches the expected types in the database, helping maintain data integrity and prevent errors during data flow operations.
DbTypeCheck will check incoming rows to ensure their compatibility with the data types of corresponding columns in a designated table. By supplying a TableName and a ConnectionManager, the component automatically retrieves a TableDefinition from the source. Additionally, ColumnMapping, akin to that used in DbDestination, can be provided. DbTypeCheck verifies if each property’s data type and value in the incoming row match the mapped column.
Designed as a transformation component, DbTypeCheck has two outputs. The primary output, utilized through LinkTo, redirects all rows that pass the type check. Flawed rows are redirected to other components using the LinkFlawedTo method. The type check’s behavior can be tailored through various properties of the component.
By default, DbTypeCheck retrieves the table definition from the database using the specified TableName and ConnectionManager. However, you can specify your own table definition, particularly useful when only specific columns need validation. For instance, you might use TableDefinition.FromTableName to obtain the complete table definition from an existing table and then modify it as required.
Records that align with the table’s schema are redirected using the standard LinkTo(..) method. Flawed records can be rerouted using the LinkFlawedTo(IDataFlowDestination<TInput>) method. Omitting LinkFlawedTo(..) causes flawed records to throw an exception, potentially halting the data flow upon encountering a flawed record. Alternatively, using the default LinkErrorTo(..) method allows records that trigger exceptions to be rerouted as ETLBoxError into an error data flow.
Column mapping in DbTypeCheck mirrors the approach used in DbDestination. It is advisable to use the same column mapping for DbTypeCheck as in your DbDestination. The mapping can be defined either through attributes on a POCO (as in the earlier example) or by passing an array to the ColumnMapping attribute for dynamic objects.
If you aim to overwrite existing identity columns (a.k.a auto-increment or serial columns) in your target table, DbTypeCheck allows you to include identity columns in your type check.
These checks apply to CHAR/VARCHAR and BINARY/VARBINARY columns, respectively. By default, if a value’s length exceeds the maximum length of the corresponding column, the record is identified as flawed.
DbTypeCheck, like all ETLBox components, supports both strongly-typed objects (e.g., DbTypeCheck<MyRow>) and dynamic ExpandoObject (either DbTypeCheck<ExpandoObject> or DbTypeCheck).
The DbTypeCheck component can now capture detailed information about why a type check failed and store this information in the ConversionError property of a POCO or a dynamic object. This enhancement helps in diagnosing and debugging data issues by providing clear error messages for each flawed record.