Class DataChangeExtensions
Extension methods for retrieving typed values from data changes in CDC (Change Data Capture) events.
public static class DataChangeExtensions
- Inheritance
-
DataChangeExtensions
- Inherited Members
Methods
GetNewValue<T>(DataChangeEvent, string, T)
Retrieves the new value of a specified column from a data change event and converts it to the specified type.
public static T GetNewValue<T>(this DataChangeEvent changeEvent, string columnName, T defaultValue = default)
Parameters
changeEventDataChangeEventThe DataChangeEvent containing the changes.
columnNamestringThe name of the column to retrieve the value from.
defaultValueTThe default value to return if the column is not found or its value is null.
Returns
- T
The new value of the column converted to type
T, or thedefaultValueif the column is not found or its value is null.
Type Parameters
TThe expected type of the column's new value.
GetNewValue<T>(IEnumerable<DataChange>, string, T)
Retrieves the new value of a specified column from a collection of data changes and converts it to the specified type.
public static T GetNewValue<T>(this IEnumerable<DataChange> changes, string columnName, T defaultValue = default)
Parameters
changesIEnumerable<DataChange>The collection of DataChange objects representing changes in data.
columnNamestringThe name of the column to retrieve the value from.
defaultValueTThe default value to return if the column is not found or its value is null.
Returns
- T
The new value of the column converted to type
T, or thedefaultValueif the column is not found or its value is null.
Type Parameters
TThe expected type of the column's new value.
Exceptions
- InvalidOperationException
Thrown if the column's value is null and the specified type
Tis not nullable, or if the value cannot be converted to the specified type.
GetOldValue<T>(DataChangeEvent, string, T)
Retrieves the old (previous) value of a specified column from a data change event and converts it to the specified type.
public static T GetOldValue<T>(this DataChangeEvent changeEvent, string columnName, T defaultValue = default)
Parameters
changeEventDataChangeEventThe DataChangeEvent containing the changes.
columnNamestringThe name of the column to retrieve the value from.
defaultValueTThe default value to return if the column is not found or its value is null.
Returns
- T
The old value of the column converted to type
T, or thedefaultValueif the column is not found or its value is null.
Type Parameters
TThe expected type of the column's old value.
GetOldValue<T>(IEnumerable<DataChange>, string, T)
Retrieves the old (previous) value of a specified column from a collection of data changes and converts it to the specified type.
public static T GetOldValue<T>(this IEnumerable<DataChange> changes, string columnName, T defaultValue = default)
Parameters
changesIEnumerable<DataChange>The collection of DataChange objects representing changes in data.
columnNamestringThe name of the column to retrieve the value from.
defaultValueTThe default value to return if the column is not found or its value is null.
Returns
- T
The old value of the column converted to type
T, or thedefaultValueif the column is not found or its value is null.
Type Parameters
TThe expected type of the column's old value.
Exceptions
- InvalidOperationException
Thrown if the column's value is null and the specified type
Tis not nullable, or if the value cannot be converted to the specified type.