Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new ADO.NET async APIs #16426

Merged
merged 1 commit into from
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/EFCore.Relational/Diagnostics/DbConnectionInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public virtual Task ConnectionOpenedAsync(
=> result;

/// <summary>
/// Called just before EF intends to call <see cref="DbConnection.Close()" /> in an async context.
/// Called just before EF intends to call <see cref="DbConnection.CloseAsync()" /> in an async context.
/// </summary>
/// <param name="connection"> The connection. </param>
/// <param name="eventData"> Contextual information about the connection. </param>
Expand Down Expand Up @@ -143,7 +143,7 @@ public virtual void ConnectionClosed(
}

/// <summary>
/// Called just after EF has called <see cref="DbConnection.Close()" />.
/// Called just after EF has called <see cref="DbConnection.CloseAsync()" />.
/// </summary>
/// <param name="connection"> The connection. </param>
/// <param name="eventData"> Contextual information about the connection. </param>
Expand Down
14 changes: 7 additions & 7 deletions src/EFCore.Relational/Diagnostics/DbTransactionInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public virtual DbTransaction TransactionStarted(
=> result;

/// <summary>
/// Called just before EF intends to call <see cref="DbConnection.BeginTransaction(IsolationLevel)" />.
/// Called just before EF intends to call <see cref="DbConnection.BeginTransactionAsync(IsolationLevel, CancellationToken)" />.
/// </summary>
/// <param name="connection"> The connection. </param>
/// <param name="eventData"> Contextual information about connection and transaction. </param>
Expand All @@ -92,7 +92,7 @@ public virtual DbTransaction TransactionStarted(

/// <summary>
/// <para>
/// Called immediately after EF calls <see cref="DbConnection.BeginTransaction(IsolationLevel)" />.
/// Called immediately after EF calls <see cref="DbConnection.BeginTransactionAsync(IsolationLevel, CancellationToken)" />.
/// </para>
/// <para>
/// This method is still called if an interceptor suppressed creation in <see cref="IDbTransactionInterceptor.TransactionStarting" />.
Expand All @@ -102,7 +102,7 @@ public virtual DbTransaction TransactionStarted(
/// <param name="connection"> The connection. </param>
/// <param name="eventData"> Contextual information about connection and transaction. </param>
/// <param name="result">
/// The result of the call to <see cref="DbConnection.BeginTransaction(IsolationLevel)" />.
/// The result of the call to <see cref="DbConnection.BeginTransactionAsync(IsolationLevel, CancellationToken)" />.
/// This value is typically used as the return value for the implementation of this method.
/// </param>
/// <param name="cancellationToken"> The cancellation token. </param>
Expand Down Expand Up @@ -197,7 +197,7 @@ public virtual void TransactionCommitted(
}

/// <summary>
/// Called just before EF intends to call <see cref="DbTransaction.Commit" />.
/// Called just before EF intends to call <see cref="DbTransaction.CommitAsync" />.
/// </summary>
/// <param name="transaction"> The transaction. </param>
/// <param name="eventData"> Contextual information about connection and transaction. </param>
Expand All @@ -222,7 +222,7 @@ public virtual void TransactionCommitted(
=> Task.FromResult(result);

/// <summary>
/// Called immediately after EF calls <see cref="DbTransaction.Commit" />.
/// Called immediately after EF calls <see cref="DbTransaction.CommitAsync" />.
/// </summary>
/// <param name="transaction"> The transaction. </param>
/// <param name="eventData"> Contextual information about connection and transaction. </param>
Expand Down Expand Up @@ -269,7 +269,7 @@ public virtual void TransactionRolledBack(
}

/// <summary>
/// Called just before EF intends to call <see cref="DbTransaction.Rollback" />.
/// Called just before EF intends to call <see cref="DbTransaction.RollbackAsync" />.
/// </summary>
/// <param name="transaction"> The transaction. </param>
/// <param name="eventData"> Contextual information about connection and transaction. </param>
Expand All @@ -294,7 +294,7 @@ public virtual void TransactionRolledBack(
=> Task.FromResult(result);

/// <summary>
/// Called immediately after EF calls <see cref="DbTransaction.Rollback" />.
/// Called immediately after EF calls <see cref="DbTransaction.RollbackAsync" />.
/// </summary>
/// <param name="transaction"> The transaction. </param>
/// <param name="eventData"> Contextual information about connection and transaction. </param>
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.Relational/Diagnostics/IDbConnectionInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Task ConnectionOpenedAsync(
CancellationToken cancellationToken = default);

/// <summary>
/// Called just before EF intends to call <see cref="DbConnection.Close()" />.
/// Called just before EF intends to call <see cref="DbConnection.CloseAsync()" />.
/// </summary>
/// <param name="connection"> The connection. </param>
/// <param name="eventData"> Contextual information about the connection. </param>
Expand Down Expand Up @@ -152,7 +152,7 @@ void ConnectionClosed(
[NotNull] ConnectionEndEventData eventData);

/// <summary>
/// Called just after EF has called <see cref="DbConnection.Close()" />.
/// Called just after EF has called <see cref="DbConnection.CloseAsync()" />.
/// </summary>
/// <param name="connection"> The connection. </param>
/// <param name="eventData"> Contextual information about the connection. </param>
Expand Down
14 changes: 7 additions & 7 deletions src/EFCore.Relational/Diagnostics/IDbTransactionInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ DbTransaction TransactionStarted(
[CanBeNull] DbTransaction result);

/// <summary>
/// Called just before EF intends to call <see cref="DbConnection.BeginTransaction(IsolationLevel)" />.
/// Called just before EF intends to call <see cref="DbConnection.BeginTransactionAsync(IsolationLevel, CancellationToken)" />.
/// </summary>
/// <param name="connection"> The connection. </param>
/// <param name="eventData"> Contextual information about connection and transaction. </param>
Expand All @@ -108,7 +108,7 @@ DbTransaction TransactionStarted(

/// <summary>
/// <para>
/// Called immediately after EF calls <see cref="DbConnection.BeginTransaction(IsolationLevel)" />.
/// Called immediately after EF calls <see cref="DbConnection.BeginTransactionAsync(IsolationLevel, CancellationToken)" />.
/// </para>
/// <para>
/// This method is still called if an interceptor suppressed creation in <see cref="TransactionStarting" />.
Expand All @@ -118,7 +118,7 @@ DbTransaction TransactionStarted(
/// <param name="connection"> The connection. </param>
/// <param name="eventData"> Contextual information about connection and transaction. </param>
/// <param name="result">
/// The result of the call to <see cref="DbConnection.BeginTransaction(IsolationLevel)" />.
/// The result of the call to <see cref="DbConnection.BeginTransactionAsync(IsolationLevel, CancellationToken)" />.
/// This value is typically used as the return value for the implementation of this method.
/// </param>
/// <param name="cancellationToken"> The cancellation token. </param>
Expand Down Expand Up @@ -210,7 +210,7 @@ void TransactionCommitted(
[NotNull] TransactionEndEventData eventData);

/// <summary>
/// Called just before EF intends to call <see cref="DbTransaction.Commit" />.
/// Called just before EF intends to call <see cref="DbTransaction.CommitAsync" />.
/// </summary>
/// <param name="transaction"> The transaction. </param>
/// <param name="eventData"> Contextual information about connection and transaction. </param>
Expand All @@ -234,7 +234,7 @@ void TransactionCommitted(
CancellationToken cancellationToken = default);

/// <summary>
/// Called immediately after EF calls <see cref="DbTransaction.Commit" />.
/// Called immediately after EF calls <see cref="DbTransaction.CommitAsync" />.
/// </summary>
/// <param name="transaction"> The transaction. </param>
/// <param name="eventData"> Contextual information about connection and transaction. </param>
Expand Down Expand Up @@ -277,7 +277,7 @@ void TransactionRolledBack(
[NotNull] TransactionEndEventData eventData);

/// <summary>
/// Called just before EF intends to call <see cref="DbTransaction.Rollback" />.
/// Called just before EF intends to call <see cref="DbTransaction.RollbackAsync" />.
/// </summary>
/// <param name="transaction"> The transaction. </param>
/// <param name="eventData"> Contextual information about connection and transaction. </param>
Expand All @@ -301,7 +301,7 @@ void TransactionRolledBack(
CancellationToken cancellationToken = default);

/// <summary>
/// Called immediately after EF calls <see cref="DbTransaction.Rollback" />.
/// Called immediately after EF calls <see cref="DbTransaction.RollbackAsync" />.
/// </summary>
/// <param name="transaction"> The transaction. </param>
/// <param name="eventData"> Contextual information about connection and transaction. </param>
Expand Down
6 changes: 3 additions & 3 deletions src/EFCore.Relational/Storage/RelationalConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public virtual async Task<IDbContextTransaction> BeginTransactionAsync(

var dbTransaction = interceptionResult.HasValue
? interceptionResult.Value.Result
: DbConnection.BeginTransaction(isolationLevel); // Use BeginTransactionAsync when available
: await DbConnection.BeginTransactionAsync(isolationLevel, cancellationToken);

dbTransaction = await Dependencies.TransactionLogger.TransactionStartedAsync(
this,
Expand Down Expand Up @@ -451,7 +451,7 @@ public virtual async Task<bool> OpenAsync(CancellationToken cancellationToken, b
{
if (DbConnection.State == ConnectionState.Broken)
{
DbConnection.Close();
await DbConnection.CloseAsync();
}

var wasOpened = false;
Expand Down Expand Up @@ -684,7 +684,7 @@ public virtual async Task<bool> CloseAsync()
{
if (interceptionResult == null)
{
DbConnection.Close(); // Since no CloseAsync yet
await DbConnection.CloseAsync();
}

wasClosed = true;
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore.Relational/Storage/RelationalTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public virtual async Task CommitAsync(CancellationToken cancellationToken = defa

if (interceptionResult == null)
{
_dbTransaction.Commit();
await _dbTransaction.CommitAsync(cancellationToken);
}

await Logger.TransactionCommittedAsync(
Expand Down Expand Up @@ -242,7 +242,7 @@ public virtual async Task RollbackAsync(CancellationToken cancellationToken = de

if (interceptionResult == null)
{
_dbTransaction.Rollback(); // Use RollbackAsync when available
await _dbTransaction.RollbackAsync(cancellationToken);
}

await Logger.TransactionRolledBackAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,21 +394,24 @@ private static async Task<T> ExecuteCommandAsync<T>(
{
if (connection.State != ConnectionState.Closed)
{
connection.Close();
await connection.CloseAsync();
}

await connection.OpenAsync();
try
{
using (var transaction = useTransaction ? connection.BeginTransaction() : null)
using (var transaction = useTransaction ? await connection.BeginTransactionAsync() : null)
{
T result;
using (var command = CreateCommand(connection, sql, parameters))
{
result = await executeAsync(command);
}

transaction?.Commit();
if (transaction != null)
{
await transaction.CommitAsync();
}

return result;
}
Expand All @@ -417,7 +420,7 @@ private static async Task<T> ExecuteCommandAsync<T>(
{
if (connection.State != ConnectionState.Closed)
{
connection.Close();
await connection.CloseAsync();
}
}
}
Expand Down