Table of Contents

Method ExecuteScalar

Namespace
Open.Database.Extensions.Synchronous
Assembly
Open.Database.Extensions.Core.dll

ExecuteScalar(IExecuteCommand)

Executes the command with ExecuteScalar().

public static object? ExecuteScalar(this IExecuteCommand command)

Parameters

command IExecuteCommand

The command to execute.

Returns

object

The raw value the provider returns: Value when the column is NULL and null when there is no row, which is how to tell the two apart. Use ExecuteScalar<T>() to convert it.

ExecuteScalar<T>(IExecuteCommand)

Executes the command with ExecuteScalar() and converts the value to the expected type, as Map<T>() converts a column.

public static T ExecuteScalar<T>(this IExecuteCommand command)

Parameters

command IExecuteCommand

The command to execute.

Returns

T

The value, converted to T: a value that is already a T is returned as is, an integer is converted to another integer type with a range check, and so on for the other conversions Map<T>() makes. null when there was no row and T takes null; an error when there was no row and T is a non-nullable value type; null when the result is NULL and T takes it.

Type Parameters

T

The type to convert the value to.

Exceptions

ValueMappingException

The value does not convert to T, or is out of its range (the conversion's own error is the inner exception), there was no row or it is NULL and T is a non-nullable value type.

ExecuteScalar<T>(IExecuteCommand, Func<object?, T>)

Executes the command with ExecuteScalar() and passes the value to a transform.

public static T ExecuteScalar<T>(this IExecuteCommand command, Func<object?, T> transform)

Parameters

command IExecuteCommand

The command to execute.

transform Func<object, T>

The function that converts the value. It receives null when the column is NULL or there is no row, never DBNull; any other value is passed unchanged.

Returns

T

The value returned from the transform.

Type Parameters

T

The type expected.

Exceptions

ArgumentNullException

transform is null.