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
connectionDbConnectiontransactionDbTransaction
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
sqlstringparametersSqlParameterscancellationTokenCancellationToken
Returns
- Task<T>
Type Parameters
T
Exceptions
- ArgumentException
sqlis null or whitespace.- InvalidOperationException
The connection is not open, the result is a database null and
Tis a non-nullable value type, or the result cannot be converted toT.
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
sqlstringparametersSqlParameterscancellationTokenCancellationToken
Returns
Exceptions
- ArgumentException
sqlis null or whitespace.- InvalidOperationException
The connection is not open.