Class DataUtils
Utility class for mapping data from IDataRecord or IDataReader to objects.
public static class DataUtils
- Inheritance
-
DataUtils
- Inherited Members
Methods
AsEnumerable<T>(IDataReader)
Converts the results from an IDataReader into an IEnumerable of type T.
public static IEnumerable<T> AsEnumerable<T>(this IDataReader reader) where T : new()
Parameters
readerIDataReaderThe IDataReader containing the data.
Returns
- IEnumerable<T>
An IEnumerable of T, where each item is populated with data from a record in the reader.
Type Parameters
TType to which each record should be converted. Must have a parameterless constructor.
FillObject(IDataRecord, object)
Populates an object's fields or properties from an IDataRecord.
public static void FillObject(this IDataRecord record, object obj)
Parameters
recordIDataRecordThe IDataRecord containing the data.
objobjectThe object to populate.
GetDbType(object?)
Maps a value to the corresponding DbType.
public static DbType GetDbType(object? value)
Parameters
Returns
GetDbType(Type)
public static DbType GetDbType(Type type)
Parameters
Returns
GetDbType<T>(T)
Maps a value to the corresponding DbType.
public static DbType GetDbType<T>(T value)
Parameters
valueTValue for which to determine the DbType.
Returns
Type Parameters
T
ToDbValue(object?)
Converts a nullable value to an object suitable for database commands.
public static object ToDbValue(this object? value)
Parameters
valueobjectThe value to convert.
Returns
ToObject<T>(IDataRecord)
Converts an IDataRecord to an instance of type T.
public static T ToObject<T>(this IDataRecord record) where T : new()
Parameters
recordIDataRecordThe IDataRecord to convert.
Returns
- T
An object of type T populated with data from the record.
Type Parameters
TType to which the record should be converted. Must have a parameterless constructor.