DataContext
Implements abstraction over non-persistent database connection that could be released after query or transaction execution.
Gets or sets flag to close context after query execution or leave it open.
Gets or sets command execution timeout in seconds.
Negative timeout value means that default timeout will be used.
0 timeout value corresponds to infinite timeout.
By default timeout is not set and default value for current provider used.
Gets initial value for database connection configuration name.
Gets initial value for database connection string.
Gets or sets context identifier. Uses provider's name by default.
Gets database provider implementation.
Gets or sets option to force inline parameter values as literals into command text. If parameter inlining not supported
for specific value type, it will be used as parameter.
Gets or sets status of Multiple Active Result Sets (MARS) feature. This feature available only for
SQL Azure and SQL Server 2005+.
Gets or sets option to dispose underlying connection after use.
Default value: false.
Contains text of last command, sent to database using current context.
Gets or sets mapping schema. Uses provider's mapping schema by default.
Gets list of query hints (writable collection), that will be used only for next query, executed through current context.
Gets or sets trace handler, used for data connection instance.
Gets list of query hints (writable collection), that will be used for all queries, executed through current context.
Event, triggered before underlying connection closed on context disposal or closing.
Not fired, if context doesn't have active connection (bug?).
public DataContext()
Creates data context using default database configuration.
DefaultConfiguration for more details.
Creates data context using specific database configuration.
Creates data context using specific data provider implementation and connection string.
Creates data context using specified database provider and connection string.
Starts new transaction for current context with specified isolation level.
If connection already has transaction, it will be rolled back.
Starts new transaction for current context with default isolation level.
If connection already has transaction, it will be rolled back.
public virtual Task<DataContextTransaction> BeginTransactionAsync(IsolationLevel level, CancellationToken cancellationToken = default)
Starts new transaction asynchronously for current context with specified isolation level.
If connection already has transaction, it will be rolled back.
public virtual Task<DataContextTransaction> BeginTransactionAsync(bool autoCommitOnDispose = true, CancellationToken cancellationToken = default)
Starts new transaction asynchronously for current context with default isolation level.
If connection already has transaction, it will be rolled back.
protected virtual DataConnection CloneDataConnection(DataConnection currentConnection, IAsyncDbTransaction dbTransaction, IAsyncDbConnection dbConnection)
Creates instance of DataConnection class, attached to same database connection/transaction.
Used by Clone API only if IsMarsEnabled
is true and there is an active connection associated with current context.
dbConnection and dbTransaction parameters are mutually exclusive.
One and only one parameter will have value - if there is active transaction, dbTransaction
parameter value provided, otherwise dbConnection parameter has value.
Creates instance of DataConnection class, used by context internally.
Closes underlying connection and fires OnClosing event (only if connection existed).
Closes underlying connection and fires OnClosing event (only if connection existed).