Table of Contents

Class DataSession

Namespace
FluentCommand
Assembly
FluentCommand.dll

A fluent class for a data session.

public class DataSession : DisposableBase, IDataSession, IDisposable, IAsyncDisposable
Inheritance
DataSession
Implements
Derived
Inherited Members
Extension Methods

Constructors

DataSession(IDataConfiguration)

Initializes a new instance of the DataSession class.

public DataSession(IDataConfiguration dataConfiguration)

Parameters

dataConfiguration IDataConfiguration

The configuration for the session

Exceptions

ArgumentNullException

dataConfiguration is null

DataSession(DbConnection, bool, IDataCache, IQueryGenerator, IDataQueryLogger)

Initializes a new instance of the DataSession class.

public DataSession(DbConnection connection, bool disposeConnection = true, IDataCache cache = null, IQueryGenerator queryGenerator = null, IDataQueryLogger logger = null)

Parameters

connection DbConnection

The DbConnection to use for the session.

disposeConnection bool

if set to true dispose connection with this session.

cache IDataCache

The IDataCache used to cached results of queries.

queryGenerator IQueryGenerator

The query generator provider.

logger IDataQueryLogger

The logger delegate for writing log messages.

Exceptions

ArgumentNullException

connection is null

ArgumentException

Invalid connection string on connection instance.

DataSession(DbTransaction, bool, IDataCache, IQueryGenerator, IDataQueryLogger)

Initializes a new instance of the DataSession class.

public DataSession(DbTransaction transaction, bool disposeConnection = false, IDataCache cache = null, IQueryGenerator queryGenerator = null, IDataQueryLogger logger = null)

Parameters

transaction DbTransaction

The DbTransaction to use for the session.

disposeConnection bool

if set to true dispose connection with this session.

cache IDataCache

The IDataCache used to cached results of queries.

queryGenerator IQueryGenerator

The query generator provider.

logger IDataQueryLogger

The logger delegate for writing log messages.

Exceptions

ArgumentNullException

transaction is null

ArgumentException

Invalid connection string on transaction instance.

Properties

Cache

Gets the underlying IDataCache for the session.

public IDataCache Cache { get; }

Property Value

IDataCache

Connection

Gets the underlying DbConnection for the session.

public DbConnection Connection { get; }

Property Value

DbConnection

QueryGenerator

Gets the query generator provider.

public IQueryGenerator QueryGenerator { get; }

Property Value

IQueryGenerator

The query generator provider.

QueryLogger

Gets the data command query logger.

public IDataQueryLogger QueryLogger { get; }

Property Value

IDataQueryLogger

The data command query logger.

Transaction

Gets the underlying DbTransaction for the session.

public DbTransaction Transaction { get; }

Property Value

DbTransaction

Methods

BeginTransaction(IsolationLevel)

Starts a database transaction with the specified isolation level.

public DbTransaction BeginTransaction(IsolationLevel isolationLevel = IsolationLevel.Unspecified)

Parameters

isolationLevel IsolationLevel

Specifies the isolation level for the transaction.

Returns

DbTransaction

A DbTransaction representing the new transaction.

BeginTransactionAsync(IsolationLevel, CancellationToken)

Starts a database transaction with the specified isolation level.

public Task<DbTransaction> BeginTransactionAsync(IsolationLevel isolationLevel = IsolationLevel.Unspecified, CancellationToken cancellationToken = default)

Parameters

isolationLevel IsolationLevel

Specifies the isolation level for the transaction.

cancellationToken CancellationToken

The cancellation instruction.

Returns

Task<DbTransaction>

A DbTransaction representing the new transaction.

DisposeManagedResources()

Disposes the managed resources.

protected override void DisposeManagedResources()

DisposeResourcesAsync()

Disposes the managed resources.

protected override ValueTask DisposeResourcesAsync()

Returns

ValueTask

EnsureConnection()

Ensures the connection is open.

public void EnsureConnection()

Exceptions

InvalidOperationException

Failed to open connection

EnsureConnectionAsync(CancellationToken)

Ensures the connection is open asynchronous.

public Task EnsureConnectionAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

The cancellation instruction.

Returns

Task

A task representing the asynchronous operation.

Exceptions

InvalidOperationException

Failed to open connection

ReleaseConnection()

Releases the connection.

public void ReleaseConnection()

ReleaseConnectionAsync()

Releases the connection.

public Task ReleaseConnectionAsync()

Returns

Task

Sql(string)

Starts a data command with the specified SQL.

public IDataCommand Sql(string sql)

Parameters

sql string

The SQL statement.

Returns

IDataCommand

A fluent interface to a data command.

StoredProcedure(string)

Starts a data command with the specified stored procedure name.

public IDataCommand StoredProcedure(string storedProcedureName)

Parameters

storedProcedureName string

Name of the stored procedure.

Returns

IDataCommand

A fluent interface to a data command.

See Also