Interface IQueryExecutor
Executes a prepared query command and materializes its result.
The convenience overloads (parameterless ToList, Any, cancellation-only
variants) live in DataContextExtensions.
public interface IQueryExecutor
- Extension Methods
Methods
ExecuteScalar<TResult>(IPreparedQueryCommand<TResult>, object[]?, bool, CancellationToken)
Asynchronously executes the query and returns its scalar value.
Task<TResult?> ExecuteScalar<TResult>(IPreparedQueryCommand<TResult> preparedQueryCommand, object[]? @params, bool throwIfNull, CancellationToken cancellationToken)
Parameters
preparedQueryCommandIPreparedQueryCommand<TResult>The compiled query to execute.
paramsobject[]The positional parameter values bound to the query, or null for none.
throwIfNullboolWhether to throw when the scalar is null instead of returning it.
cancellationTokenCancellationTokenCancels execution of the query.
Returns
Type Parameters
TResultThe scalar result type.
ExecuteScalar<TResult>(IPreparedQueryCommand<TResult>, ReadOnlySpan<object?>, bool)
Executes the query and returns its scalar value.
TResult? ExecuteScalar<TResult>(IPreparedQueryCommand<TResult> preparedQueryCommand, ReadOnlySpan<object?> @params, bool throwIfNull)
Parameters
preparedQueryCommandIPreparedQueryCommand<TResult>The compiled query to execute.
paramsReadOnlySpan<object>The positional parameter values bound to the query.
throwIfNullboolWhether to throw when the scalar is null instead of returning it.
Returns
- TResult
The scalar value, or null when none was returned.
Type Parameters
TResultThe scalar result type.
FirstAsync<TResult>(IPreparedQueryCommand<TResult>, object[]?, CancellationToken)
Asynchronously returns the first result row, throwing when the query returns none.
Task<TResult> FirstAsync<TResult>(IPreparedQueryCommand<TResult> preparedQueryCommand, object[]? @params, CancellationToken cancellationToken)
Parameters
preparedQueryCommandIPreparedQueryCommand<TResult>The compiled query to execute.
paramsobject[]The positional parameter values bound to the query, or null for none.
cancellationTokenCancellationTokenCancels reading of the result row.
Returns
- Task<TResult>
A task producing the first result row.
Type Parameters
TResultThe result element type.
FirstOrDefaultAsync<TResult>(IPreparedQueryCommand<TResult>, object[]?, CancellationToken)
Asynchronously returns the first result row, or the default value when the query returns none.
Task<TResult?> FirstOrDefaultAsync<TResult>(IPreparedQueryCommand<TResult> preparedQueryCommand, object[]? @params, CancellationToken cancellationToken)
Parameters
preparedQueryCommandIPreparedQueryCommand<TResult>The compiled query to execute.
paramsobject[]The positional parameter values bound to the query, or null for none.
cancellationTokenCancellationTokenCancels reading of the result row.
Returns
- Task<TResult>
A task producing the first result row, or the default value of
TResult.
Type Parameters
TResultThe result element type.
FirstOrDefault<TResult>(IPreparedQueryCommand<TResult>, ReadOnlySpan<object?>)
Returns the first result row, or the default value when the query returns none.
TResult? FirstOrDefault<TResult>(IPreparedQueryCommand<TResult> preparedQueryCommand, ReadOnlySpan<object?> @params)
Parameters
preparedQueryCommandIPreparedQueryCommand<TResult>The compiled query to execute.
paramsReadOnlySpan<object>The positional parameter values bound to the query.
Returns
- TResult
The first result row, or the default value of
TResult.
Type Parameters
TResultThe result element type.
First<TResult>(IPreparedQueryCommand<TResult>, ReadOnlySpan<object?>)
Returns the first result row, throwing when the query returns none.
TResult First<TResult>(IPreparedQueryCommand<TResult> preparedQueryCommand, ReadOnlySpan<object?> @params)
Parameters
preparedQueryCommandIPreparedQueryCommand<TResult>The compiled query to execute.
paramsReadOnlySpan<object>The positional parameter values bound to the query.
Returns
- TResult
The first result row.
Type Parameters
TResultThe result element type.
SingleAsync<TResult>(IPreparedQueryCommand<TResult>, object[]?, CancellationToken)
Asynchronously returns the single result row, throwing when the query returns none or more than one.
Task<TResult> SingleAsync<TResult>(IPreparedQueryCommand<TResult> preparedQueryCommand, object[]? @params, CancellationToken cancellationToken)
Parameters
preparedQueryCommandIPreparedQueryCommand<TResult>The compiled query to execute.
paramsobject[]The positional parameter values bound to the query, or null for none.
cancellationTokenCancellationTokenCancels reading of the result row.
Returns
- Task<TResult>
A task producing the single result row.
Type Parameters
TResultThe result element type.
SingleOrDefaultAsync<TResult>(IPreparedQueryCommand<TResult>, object[]?, CancellationToken)
Asynchronously returns the single result row, or the default value when the query returns none.
Task<TResult?> SingleOrDefaultAsync<TResult>(IPreparedQueryCommand<TResult> preparedQueryCommand, object[]? @params, CancellationToken cancellationToken)
Parameters
preparedQueryCommandIPreparedQueryCommand<TResult>The compiled query to execute.
paramsobject[]The positional parameter values bound to the query, or null for none.
cancellationTokenCancellationTokenCancels reading of the result row.
Returns
- Task<TResult>
A task producing the single result row, or the default value of
TResult.
Type Parameters
TResultThe result element type.
SingleOrDefault<TResult>(IPreparedQueryCommand<TResult>, ReadOnlySpan<object?>)
Returns the single result row, or the default value when the query returns none, throwing when it returns more than one.
TResult? SingleOrDefault<TResult>(IPreparedQueryCommand<TResult> preparedQueryCommand, ReadOnlySpan<object?> @params)
Parameters
preparedQueryCommandIPreparedQueryCommand<TResult>The compiled query to execute.
paramsReadOnlySpan<object>The positional parameter values bound to the query.
Returns
- TResult
The single result row, or the default value of
TResult.
Type Parameters
TResultThe result element type.
Single<TResult>(IPreparedQueryCommand<TResult>, ReadOnlySpan<object?>)
Returns the single result row, throwing when the query returns none or more than one.
TResult Single<TResult>(IPreparedQueryCommand<TResult> preparedQueryCommand, ReadOnlySpan<object?> @params)
Parameters
preparedQueryCommandIPreparedQueryCommand<TResult>The compiled query to execute.
paramsReadOnlySpan<object>The positional parameter values bound to the query.
Returns
- TResult
The single result row.
Type Parameters
TResultThe result element type.
ToListAsync<TResult>(IPreparedQueryCommand<TResult>, object[]?, CancellationToken)
Asynchronously materializes all result rows into a list.
Task<List<TResult>> ToListAsync<TResult>(IPreparedQueryCommand<TResult> preparedQueryCommand, object[]? @params, CancellationToken cancellationToken)
Parameters
preparedQueryCommandIPreparedQueryCommand<TResult>The compiled query to execute.
paramsobject[]The positional parameter values bound to the query, or null for none.
cancellationTokenCancellationTokenCancels reading of the result rows.
Returns
Type Parameters
TResultThe result element type.
ToList<TResult>(IPreparedQueryCommand<TResult>, ReadOnlySpan<object?>)
Materializes all result rows into a list.
List<TResult> ToList<TResult>(IPreparedQueryCommand<TResult> preparedQueryCommand, ReadOnlySpan<object?> @params)
Parameters
preparedQueryCommandIPreparedQueryCommand<TResult>The compiled query to execute.
paramsReadOnlySpan<object>The positional parameter values bound to the query.
Returns
- List<TResult>
The materialized result rows.
Type Parameters
TResultThe result element type.