RelationalDatabaseFacadeExtensions RelationalDatabaseFacadeExtensions Class

Definition

public static class RelationalDatabaseFacadeExtensions
Public Module RelationalDatabaseFacadeExtensions
Inheritance
System.ObjectSystem.Object
RelationalDatabaseFacadeExtensionsRelationalDatabaseFacadeExtensions

Inherited Members

System.Object

System.Object.ToString()System.Object.ToString()
System.Object.Equals(System.Object)System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()System.Object.GetHashCode()
System.Object.GetType()System.Object.GetType()
System.Object.MemberwiseClone()System.Object.MemberwiseClone()

Methods

BeginTransaction(DatabaseFacade, IsolationLevel) BeginTransaction(DatabaseFacade, IsolationLevel)

public static IDbContextTransaction BeginTransaction(this DatabaseFacade databaseFacade, IsolationLevel isolationLevel)
<ExtensionAttribute>
Public Shared Function BeginTransaction(databaseFacade As DatabaseFacade, isolationLevel As IsolationLevel) As IDbContextTransaction
Parameters
isolationLevel
System.Data.IsolationLevel System.Data.IsolationLevel
Returns

BeginTransactionAsync(DatabaseFacade, IsolationLevel, CancellationToken) BeginTransactionAsync(DatabaseFacade, IsolationLevel, CancellationToken)

public static Task<IDbContextTransaction> BeginTransactionAsync(this DatabaseFacade databaseFacade, IsolationLevel isolationLevel, CancellationToken cancellationToken = null)
<ExtensionAttribute>
Public Shared Function BeginTransactionAsync(databaseFacade As DatabaseFacade, isolationLevel As IsolationLevel, cancellationToken As CancellationToken = Nothing) As Task(Of IDbContextTransaction)
Parameters
isolationLevel
System.Data.IsolationLevel System.Data.IsolationLevel
cancellationToken
System.Threading.CancellationToken System.Threading.CancellationToken
Returns
System.Threading.Tasks.Task<IDbContextTransaction> System.Threading.Tasks.Task(Of IDbContextTransaction)

CloseConnection(DatabaseFacade) CloseConnection(DatabaseFacade)

public static void CloseConnection(this DatabaseFacade databaseFacade)
<ExtensionAttribute>
Public Shared Sub CloseConnection(databaseFacade As DatabaseFacade)
Parameters

ExecuteSqlCommand(DatabaseFacade, String, Object[]) ExecuteSqlCommand(DatabaseFacade, String, Object())

public static int ExecuteSqlCommand(this DatabaseFacade databaseFacade, string sql, params object[] parameters)
<ExtensionAttribute>
Public Shared Function ExecuteSqlCommand(databaseFacade As DatabaseFacade, sql As String, ParamArray parameters As Object()) As Integer
Parameters
sql
System.String System.String
parameters
System.Object[] System.Object()
Returns
System.Int32 System.Int32

ExecuteSqlCommandAsync(DatabaseFacade, String, CancellationToken, Object[]) ExecuteSqlCommandAsync(DatabaseFacade, String, CancellationToken, Object())

public static Task<int> ExecuteSqlCommandAsync(this DatabaseFacade databaseFacade, string sql, CancellationToken cancellationToken = null, params object[] parameters)
<ExtensionAttribute>
Public Shared Function ExecuteSqlCommandAsync(databaseFacade As DatabaseFacade, sql As String, cancellationToken As CancellationToken = Nothing, ParamArray parameters As Object()) As Task(Of Integer)
Parameters
sql
System.String System.String
cancellationToken
System.Threading.CancellationToken System.Threading.CancellationToken
parameters
System.Object[] System.Object()
Returns
System.Threading.Tasks.Task<System.Int32> System.Threading.Tasks.Task(Of System.Int32)

GetAppliedMigrations(DatabaseFacade) GetAppliedMigrations(DatabaseFacade)

Gets all migrations that have been applied to the target database.

public static IEnumerable<string> GetAppliedMigrations(this DatabaseFacade databaseFacade)
<ExtensionAttribute>
Public Shared Function GetAppliedMigrations(databaseFacade As DatabaseFacade) As IEnumerable(Of String)
Parameters
databaseFacade
DatabaseFacade DatabaseFacade

The DatabaseFacade for the context.

Returns
System.Collections.Generic.IEnumerable<System.String> System.Collections.Generic.IEnumerable(Of System.String)

The list of migrations.

GetAppliedMigrationsAsync(DatabaseFacade, CancellationToken) GetAppliedMigrationsAsync(DatabaseFacade, CancellationToken)

Asynchronously gets all migrations that have been applied to the target database.

public static Task<IEnumerable<string>> GetAppliedMigrationsAsync(this DatabaseFacade databaseFacade, CancellationToken cancellationToken = null)
<ExtensionAttribute>
Public Shared Function GetAppliedMigrationsAsync(databaseFacade As DatabaseFacade, cancellationToken As CancellationToken = Nothing) As Task(Of IEnumerable(Of String))
Parameters
databaseFacade
DatabaseFacade DatabaseFacade

The DatabaseFacade for the context.

cancellationToken
System.Threading.CancellationToken System.Threading.CancellationToken

A System.Threading.CancellationToken to observe while waiting for the task to complete.

Returns
System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<System.String>> System.Threading.Tasks.Task(Of System.Collections.Generic.IEnumerable(Of System.String))

A task that represents the asynchronous operation.

GetCommandTimeout(DatabaseFacade) GetCommandTimeout(DatabaseFacade)

public static int ? GetCommandTimeout(this DatabaseFacade databaseFacade)
<ExtensionAttribute>
Public Shared Function GetCommandTimeout(databaseFacade As DatabaseFacade) As Integer?
Parameters
Returns
System.Nullable<System.Int32> System.Nullable(Of System.Int32)

GetDbConnection(DatabaseFacade) GetDbConnection(DatabaseFacade)

public static DbConnection GetDbConnection(this DatabaseFacade databaseFacade)
<ExtensionAttribute>
Public Shared Function GetDbConnection(databaseFacade As DatabaseFacade) As DbConnection
Parameters
Returns
System.Data.Common.DbConnection System.Data.Common.DbConnection

GetMigrations(DatabaseFacade) GetMigrations(DatabaseFacade)

Gets all the migrations that are defined in the configured migrations assembly.

public static IEnumerable<string> GetMigrations(this DatabaseFacade databaseFacade)
<ExtensionAttribute>
Public Shared Function GetMigrations(databaseFacade As DatabaseFacade) As IEnumerable(Of String)
Parameters
databaseFacade
DatabaseFacade DatabaseFacade

The DatabaseFacade for the context.

Returns
System.Collections.Generic.IEnumerable<System.String> System.Collections.Generic.IEnumerable(Of System.String)

The list of migrations.

GetPendingMigrations(DatabaseFacade) GetPendingMigrations(DatabaseFacade)

Gets all migrations that are defined in the assembly but haven't been applied to the target database.

public static IEnumerable<string> GetPendingMigrations(this DatabaseFacade databaseFacade)
<ExtensionAttribute>
Public Shared Function GetPendingMigrations(databaseFacade As DatabaseFacade) As IEnumerable(Of String)
Parameters
databaseFacade
DatabaseFacade DatabaseFacade

The DatabaseFacade for the context.

Returns
System.Collections.Generic.IEnumerable<System.String> System.Collections.Generic.IEnumerable(Of System.String)

The list of migrations.

GetPendingMigrationsAsync(DatabaseFacade, CancellationToken) GetPendingMigrationsAsync(DatabaseFacade, CancellationToken)

Asynchronously gets all migrations that are defined in the assembly but haven't been applied to the target database.

public static Task<IEnumerable<string>> GetPendingMigrationsAsync(this DatabaseFacade databaseFacade, CancellationToken cancellationToken = null)
<ExtensionAttribute>
Public Shared Function GetPendingMigrationsAsync(databaseFacade As DatabaseFacade, cancellationToken As CancellationToken = Nothing) As Task(Of IEnumerable(Of String))
Parameters
databaseFacade
DatabaseFacade DatabaseFacade

The DatabaseFacade for the context.

cancellationToken
System.Threading.CancellationToken System.Threading.CancellationToken

A System.Threading.CancellationToken to observe while waiting for the task to complete.

Returns
System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<System.String>> System.Threading.Tasks.Task(Of System.Collections.Generic.IEnumerable(Of System.String))

A task that represents the asynchronous operation.

Migrate(DatabaseFacade) Migrate(DatabaseFacade)

Applies any pending migrations for the context to the database. Will create the database if it does not already exist.

Note that this API is mutually exclusive with DbContext.Database.EnsureCreated(). EnsureCreated does not use migrations to create the database and therefore the database that is created cannot be later updated using migrations.

public static void Migrate(this DatabaseFacade databaseFacade)
<ExtensionAttribute>
Public Shared Sub Migrate(databaseFacade As DatabaseFacade)
Parameters
databaseFacade
DatabaseFacade DatabaseFacade

The DatabaseFacade for the context.

MigrateAsync(DatabaseFacade, CancellationToken) MigrateAsync(DatabaseFacade, CancellationToken)

Asynchronously applies any pending migrations for the context to the database. Will create the database if it does not already exist.

Note that this API is mutually exclusive with DbContext.Database.EnsureCreated(). EnsureCreated does not use migrations to create the database and therefore the database that is created cannot be later updated using migrations.

public static Task MigrateAsync(this DatabaseFacade databaseFacade, CancellationToken cancellationToken = null)
<ExtensionAttribute>
Public Shared Function MigrateAsync(databaseFacade As DatabaseFacade, cancellationToken As CancellationToken = Nothing) As Task
Parameters
databaseFacade
DatabaseFacade DatabaseFacade

The DatabaseFacade for the context.

cancellationToken
System.Threading.CancellationToken System.Threading.CancellationToken

A System.Threading.CancellationToken to observe while waiting for the task to complete.

Returns
System.Threading.Tasks.Task System.Threading.Tasks.Task

A task that represents the asynchronous migration operation.

OpenConnection(DatabaseFacade) OpenConnection(DatabaseFacade)

public static void OpenConnection(this DatabaseFacade databaseFacade)
<ExtensionAttribute>
Public Shared Sub OpenConnection(databaseFacade As DatabaseFacade)
Parameters

OpenConnectionAsync(DatabaseFacade, CancellationToken) OpenConnectionAsync(DatabaseFacade, CancellationToken)

public static Task OpenConnectionAsync(this DatabaseFacade databaseFacade, CancellationToken cancellationToken = null)
<ExtensionAttribute>
Public Shared Function OpenConnectionAsync(databaseFacade As DatabaseFacade, cancellationToken As CancellationToken = Nothing) As Task
Parameters
cancellationToken
System.Threading.CancellationToken System.Threading.CancellationToken
Returns
System.Threading.Tasks.Task System.Threading.Tasks.Task

SetCommandTimeout(DatabaseFacade, Nullable) SetCommandTimeout(DatabaseFacade, Nullable(Of Int32))

public static void SetCommandTimeout(this DatabaseFacade databaseFacade, int ? timeout)
<ExtensionAttribute>
Public Shared Sub SetCommandTimeout(databaseFacade As DatabaseFacade, timeout As Integer?)
Parameters
timeout
System.Nullable<System.Int32> System.Nullable(Of System.Int32)

UseTransaction(DatabaseFacade, DbTransaction) UseTransaction(DatabaseFacade, DbTransaction)

public static IDbContextTransaction UseTransaction(this DatabaseFacade databaseFacade, DbTransaction transaction)
<ExtensionAttribute>
Public Shared Function UseTransaction(databaseFacade As DatabaseFacade, transaction As DbTransaction) As IDbContextTransaction
Parameters
transaction
System.Data.Common.DbTransaction System.Data.Common.DbTransaction
Returns