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
commandIExecuteCommandThe 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
commandIExecuteCommandThe command to execute.
Returns
- T
The value, converted to
T: a value that is already aTis returned as is, an integer is converted to another integer type with a range check, and so on for the other conversionsMap<T>()makes. null when there was no row andTtakes null; an error when there was no row andTis a non-nullable value type; null when the result is NULL andTtakes it.
Type Parameters
TThe 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 andTis 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
commandIExecuteCommandThe command to execute.
transformFunc<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
TThe type expected.
Exceptions
- ArgumentNullException
transformis null.