Table of Contents

Class DataUtils

Namespace
Utils.Data
Assembly
Utils.Data.dll

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

reader IDataReader

The 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

T

Type 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

record IDataRecord

The IDataRecord containing the data.

obj object

The object to populate.

GetDbType(object?)

Maps a value to the corresponding DbType.

public static DbType GetDbType(object? value)

Parameters

value object

Value for which to determine the DbType.

Returns

DbType

The inferred DbType for the given value.

GetDbType(Type)

Maps a Type to the corresponding DbType.

public static DbType GetDbType(Type type)

Parameters

type Type

Type for which to determine the DbType.

Returns

DbType

The inferred DbType for the given value.

GetDbType<T>(T)

Maps a value to the corresponding DbType.

public static DbType GetDbType<T>(T value)

Parameters

value T

Value for which to determine the DbType.

Returns

DbType

The inferred DbType for the given value.

Type Parameters

T

ToDbValue(object?)

Converts a nullable value to an object suitable for database commands.

public static object ToDbValue(this object? value)

Parameters

value object

The value to convert.

Returns

object

Value when value is null; otherwise the original value.

ToObject<T>(IDataRecord)

Converts an IDataRecord to an instance of type T.

public static T ToObject<T>(this IDataRecord record) where T : new()

Parameters

record IDataRecord

The IDataRecord to convert.

Returns

T

An object of type T populated with data from the record.

Type Parameters

T

Type to which the record should be converted. Must have a parameterless constructor.