Table of Contents

Class SqlSession

Namespace
SqlBound
Assembly
SqlBound.dll

Executes SQL against an already-open DbConnection. SqlSession never opens, closes, or otherwise owns the connection or its lifecycle — that responsibility always stays with the caller, so the same connection (and transaction) can be shared safely with other data-access libraries.

public sealed class SqlSession
Inheritance
SqlSession
Inherited Members

Constructors

SqlSession(DbConnection, DbTransaction?)

Initializes a new session over the given connection and, optionally, an existing transaction to enlist every command in.

public SqlSession(DbConnection connection, DbTransaction? transaction = null)

Parameters

connection DbConnection
transaction DbTransaction

Methods

FetchScalarAsync<T>(string, SqlParameters?, CancellationToken)

Executes a statement and returns its first column, first row as T. A database null converts to default when T can represent it (a reference type or Nullable<T>); otherwise it throws.

public Task<T?> FetchScalarAsync<T>(string sql, SqlParameters? parameters = null, CancellationToken cancellationToken = default)

Parameters

sql string
parameters SqlParameters
cancellationToken CancellationToken

Returns

Task<T>

Type Parameters

T

Exceptions

ArgumentException

sql is null or whitespace.

InvalidOperationException

The connection is not open, the result is a database null and T is a non-nullable value type, or the result cannot be converted to T.

RunAsync(string, SqlParameters?, CancellationToken)

Executes a non-query statement and returns the number of affected rows.

public Task<int> RunAsync(string sql, SqlParameters? parameters = null, CancellationToken cancellationToken = default)

Parameters

sql string
parameters SqlParameters
cancellationToken CancellationToken

Returns

Task<int>

Exceptions

ArgumentException

sql is null or whitespace.

InvalidOperationException

The connection is not open.