linq2db by Igor Tkachev, Ilya Chudin, Svyatoslav Danyliv, Dmitry Lukashenko

<PackageReference Include="linq2db" Version="3.5.0" />

.NET API 3,425,280 bytes

 DataContext

Implements abstraction over non-persistent database connection that could be released after query or transaction execution.
public bool CloseAfterUse { get; set; }

Gets or sets flag to close context after query execution or leave it open.

public int CommandTimeout { get; set; }

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.

public string ConfigurationString { get; }

Gets initial value for database connection configuration name.

public string ConnectionString { get; }

Gets initial value for database connection string.

public string ContextID { get; set; }

Gets or sets context identifier. Uses provider's name by default.

public IDataProvider DataProvider { get; }

Gets database provider implementation.

public bool InlineParameters { get; set; }

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.

public bool IsMarsEnabled { get; set; }

Gets or sets status of Multiple Active Result Sets (MARS) feature. This feature available only for SQL Azure and SQL Server 2005+.

public bool KeepConnectionAlive { get; set; }

Gets or sets option to dispose underlying connection after use. Default value: false.

public string LastQuery { get; set; }

Contains text of last command, sent to database using current context.

public MappingSchema MappingSchema { get; set; }

Gets or sets mapping schema. Uses provider's mapping schema by default.

public List<string> NextQueryHints { get; }

Gets list of query hints (writable collection), that will be used only for next query, executed through current context.

public Action<TraceInfo> OnTraceConnection { get; set; }

Gets or sets trace handler, used for data connection instance.

public List<string> QueryHints { get; }

Gets list of query hints (writable collection), that will be used for all queries, executed through current context.

public event EventHandler OnClosing

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.

public DataContext(string configurationString)

Creates data context using specific database configuration.

public DataContext(IDataProvider dataProvider, string connectionString)

Creates data context using specific data provider implementation and connection string.

public DataContext(string providerName, string connectionString)

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.

public virtual DataContextTransaction BeginTransaction(bool autoCommitOnDispose = true)

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.

protected virtual void Dispose(bool disposing)

Closes underlying connection and fires OnClosing event (only if connection existed).

protected virtual ValueTask DisposeAsync(bool disposing)

Closes underlying connection and fires OnClosing event (only if connection existed).