DatabaseExtensionsOpenAsyncT Method

This extension method is used to open a connection on a data context asynchronously when constructed.

Definition

Namespace: EWSoftware.EntityFramework
Assembly: EWSoftware.EntityFramework (in EWSoftware.EntityFramework.dll) Version: 2025.11.12.0
public static Task<T> OpenAsync<T>(
	this T dataContext,
	CancellationToken cancellationToken = default
)
where T : DbContext

Parameters

dataContext  T
The data context on which to open the connection.
cancellationToken  CancellationToken  (Optional)
An optional cancellation token

Type Parameters

T
The data context type

Return Value

TaskT
The passed data context object

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type T. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

This method can be used in conjunction with the NoTrackingT(T) extension method as shown in the example below.

Example

C#
using var dataContext = await new MyDbContext().OpenAsync();

... Execute commands ...

using var dataContext = await new MyDbContext().NoTracking().OpenAsync();

... Execute commands ...

See Also