Skip to content

Commit

Permalink
Update Dapper reference to tesolve #2.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Akopov committed Mar 19, 2018
1 parent 0d0f3de commit 9c2c455
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -159,6 +159,7 @@ ClientBin/
*.pfx
*.publishsettings
node_modules/
.vs/

# RIA/Silverlight projects
Generated_Code/
Expand Down
145 changes: 145 additions & 0 deletions src/Dapper.AmbientContext/AmbientDbContext.ProxyAsync.cs
Expand Up @@ -381,6 +381,37 @@ public async Task<dynamic> QuerySingleOrDefaultAsync(CommandDefinition command)
.ConfigureAwait(false);
}

/// <summary>
/// Execute a single-row query asynchronously using .NET 4.5
/// <see cref="System.Threading.Tasks.Task"/>.
/// </summary>
/// <param name="sql">
/// The SQL statement to execute.
/// </param>
/// <param name="param">
/// The SQL query parameters.
/// </param>
/// <param name="commandTimeout">
/// The number of seconds before command execution timeout.
/// </param>
/// <param name="commandType">
/// Determines whether the command is a stored procedure or a batch.
/// </param>
/// <returns>
/// A task representing the asynchronous operation.
/// </returns>
public async Task<dynamic> QueryFirstOrDefaultAsync(
string sql,
object param = null,
int? commandTimeout = null,
CommandType? commandType = null)
{
await PrepareConnectionAndTransactionAsync(default(CancellationToken)).ConfigureAwait(false);

return await Connection.QueryFirstOrDefaultAsync(sql, param, Transaction, commandTimeout, commandType)
.ConfigureAwait(false);
}

/// <summary>
/// Execute a single-row query asynchronously using .NET 4.5
/// <see cref="System.Threading.Tasks.Task"/>.
Expand Down Expand Up @@ -415,6 +446,37 @@ public async Task<dynamic> QuerySingleOrDefaultAsync(CommandDefinition command)
.ConfigureAwait(false);
}

/// <summary>
/// Execute a single-row query asynchronously using .NET 4.5
/// <see cref="System.Threading.Tasks.Task"/>.
/// </summary>
/// <param name="sql">
/// The SQL statement to execute.
/// </param>
/// <param name="param">
/// The SQL query parameters.
/// </param>
/// <param name="commandTimeout">
/// The number of seconds before command execution timeout.
/// </param>
/// <param name="commandType">
/// Determines whether the command is a stored procedure or a batch.
/// </param>
/// <returns>
/// A task representing the asynchronous operation.
/// </returns>
public async Task<dynamic> QuerySingleAsync(
string sql,
object param = null,
int? commandTimeout = null,
CommandType? commandType = null)
{
await PrepareConnectionAndTransactionAsync(default(CancellationToken)).ConfigureAwait(false);

return await Connection.QuerySingleAsync(sql, param, Transaction, commandTimeout, commandType)
.ConfigureAwait(false);
}

/// <summary>
/// Execute a single-row query asynchronously using .NET 4.5
/// <see cref="System.Threading.Tasks.Task"/>.
Expand Down Expand Up @@ -449,6 +511,89 @@ public async Task<dynamic> QuerySingleOrDefaultAsync(CommandDefinition command)
.ConfigureAwait(false);
}

/// <summary>
/// Execute a single-row query asynchronously using .NET 4.5
/// <see cref="System.Threading.Tasks.Task"/>.
/// </summary>
/// <typeparam name="T">
/// The return type.
/// </typeparam>
/// <param name="command">
/// The SQL command definition.
/// </param>
/// <returns>
/// A task representing the asynchronous operation.
/// </returns>
public async Task<T> QuerySingleOrDefaultAsync<T>(CommandDefinition command)
{
await PrepareConnectionAndTransactionAsync(default(CancellationToken)).ConfigureAwait(false);

return await Connection.QuerySingleOrDefaultAsync<T>(command)
.ConfigureAwait(false);
}

/// <summary>
/// Execute a single-row query asynchronously using .NET 4.5
/// <see cref="System.Threading.Tasks.Task"/>.
/// </summary>
/// <param name="sql">
/// The SQL statement to execute.
/// </param>
/// <param name="param">
/// The SQL query parameters.
/// </param>
/// <param name="commandTimeout">
/// The number of seconds before command execution timeout.
/// </param>
/// <param name="commandType">
/// Determines whether the command is a stored procedure or a batch.
/// </param>
/// <returns>
/// A task representing the asynchronous operation.
/// </returns>
public async Task<dynamic> QuerySingleOrDefaultAsync(
string sql,
object param = null,
int? commandTimeout = null,
CommandType? commandType = null)
{
await PrepareConnectionAndTransactionAsync(default(CancellationToken)).ConfigureAwait(false);

return await Connection.QuerySingleOrDefaultAsync(sql, param, Transaction, commandTimeout, commandType)
.ConfigureAwait(false);
}

/// <summary>
/// Execute a single-row query asynchronously using .NET 4.5
/// <see cref="System.Threading.Tasks.Task"/>.
/// </summary>
/// <param name="sql">
/// The SQL statement to execute.
/// </param>
/// <param name="param">
/// The SQL query parameters.
/// </param>
/// <param name="commandTimeout">
/// The number of seconds before command execution timeout.
/// </param>
/// <param name="commandType">
/// Determines whether the command is a stored procedure or a batch.
/// </param>
/// <returns>
/// A task representing the asynchronous operation.
/// </returns>
public async Task<dynamic> QueryFirstAsync(
string sql,
object param = null,
int? commandTimeout = null,
CommandType? commandType = null)
{
await PrepareConnectionAndTransactionAsync(default(CancellationToken)).ConfigureAwait(false);

return await Connection.QueryFirstAsync(sql, param, Transaction, commandTimeout, commandType)
.ConfigureAwait(false);
}

/// <summary>
/// Execute a query asynchronously using .NET 4.5
/// <see cref="System.Threading.Tasks.Task"/>.
Expand Down
4 changes: 2 additions & 2 deletions src/Dapper.AmbientContext/Dapper.AmbientContext.csproj
Expand Up @@ -5,7 +5,7 @@
<Copyright>Copyright Sergey Akopov</Copyright>
<VersionPrefix>1.4.0</VersionPrefix>
<Authors>Sergey Akopov</Authors>
<TargetFrameworks>net45;netstandard1.3</TargetFrameworks>
<TargetFrameworks>net451;netstandard1.3;netstandard2.0</TargetFrameworks>
<AssemblyName>Dapper.AmbientContext</AssemblyName>
<PackageId>Dapper.AmbientContext</PackageId>
<PackageTags>dapper;ambient;context</PackageTags>
Expand All @@ -21,7 +21,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Dapper" Version="1.50.2" />
<PackageReference Include="Dapper" Version="1.50.4" />
<PackageReference Include="System.Collections.Immutable" Version="1.4.0" />
</ItemGroup>

Expand Down
@@ -1,4 +1,4 @@
#if NETSTANDARD1_3
#if NETSTANDARD1_3 || NETSTANDARD2_0
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="LogicalCallContextStorage.cs">
// Copyright (c) 2016 Sergey Akopov
Expand Down
16 changes: 8 additions & 8 deletions src/Dapper.AmbientContext/Storage/ContextualStorageHelper.cs
Expand Up @@ -78,7 +78,7 @@ public ContextualStorageHelper(IContextualStorage storage)
/// </returns>
public IImmutableStack<IAmbientDbContext> GetStack()
{
#if NET45
#if NET451
var crossReferenceKey = _storage.GetValue<ContextualStorageItem>(AmbientDbContextStorageKey.Key);
#else
var crossReferenceKey = _storage.GetValue<string>(AmbientDbContextStorageKey.Key);
Expand All @@ -92,7 +92,7 @@ public IImmutableStack<IAmbientDbContext> GetStack()

IImmutableStack<IAmbientDbContext> value;

#if NET45
#if NET451
AmbientDbContextTable.TryGetValue(crossReferenceKey.Value, out value);
#else
AmbientDbContextTable.TryGetValue(crossReferenceKey, out value);
Expand All @@ -108,7 +108,7 @@ public IImmutableStack<IAmbientDbContext> GetStack()
/// </param>
public void SaveStack(IImmutableStack<IAmbientDbContext> stack)
{
#if NET45
#if NET451
var crossReferenceKey = _storage.GetValue<ContextualStorageItem>(AmbientDbContextStorageKey.Key);
#else
var crossReferenceKey = _storage.GetValue<string>(AmbientDbContextStorageKey.Key);
Expand All @@ -123,7 +123,7 @@ public void SaveStack(IImmutableStack<IAmbientDbContext> stack)
IImmutableStack<IAmbientDbContext> value;

// Drop the existing key and recreate because the value is immutable
#if NET45
#if NET451
if (AmbientDbContextTable.TryGetValue(crossReferenceKey.Value, out value))
{
AmbientDbContextTable.Remove(crossReferenceKey.Value);
Expand All @@ -146,30 +146,30 @@ public void SaveStack(IImmutableStack<IAmbientDbContext> stack)
/// </summary>
private void Initialize()
{
#if NET45
#if NET451
var crossReferenceKey = _storage.GetValue<ContextualStorageItem>(AmbientDbContextStorageKey.Key);
#else
var crossReferenceKey = _storage.GetValue<string>(AmbientDbContextStorageKey.Key);
#endif

if (crossReferenceKey == null)
{
#if NET45
#if NET451
crossReferenceKey = new ContextualStorageItem(Guid.NewGuid().ToString("N"));
#else
crossReferenceKey = Guid.NewGuid().ToString("N");
#endif
_storage.SetValue(AmbientDbContextStorageKey.Key, crossReferenceKey);

#if NET45
#if NET451
AmbientDbContextTable.Add(crossReferenceKey.Value, ImmutableStack.Create<IAmbientDbContext>());
#else
AmbientDbContextTable.Add(crossReferenceKey, ImmutableStack.Create<IAmbientDbContext>());
#endif
}
}

#if NET45
#if NET451
/// <summary>
/// Wraps values in storage to enable access across AppDomains. While all storage
/// mechanisms will use the same approach, it is only required for the Logical
Expand Down
Expand Up @@ -24,7 +24,7 @@
// Represents the type that implements storage on top of logical call context.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
#if NET45
#if NET451
namespace Dapper.AmbientContext.Storage
{
using System.Runtime.Remoting.Messaging;
Expand Down
Expand Up @@ -14,7 +14,7 @@ class When_calling_create_with_none_closed_database_connection
{
Establish context = () =>
{
#if NET45
#if NET451
AmbientDbContextStorageProvider.SetStorage(new LogicalCallContextStorage());
#else
AmbientDbContextStorageProvider.SetStorage(new AsyncLocalContextStorage());
Expand Down Expand Up @@ -56,7 +56,7 @@ class When_calling_create_with_closed_database_connection
{
Establish context = () =>
{
#if NET45
#if NET451
AmbientDbContextStorageProvider.SetStorage(new LogicalCallContextStorage());
#else
AmbientDbContextStorageProvider.SetStorage(new AsyncLocalContextStorage());
Expand Down
Expand Up @@ -14,7 +14,7 @@ class When_ambient_database_context_stack_is_empty
{
Establish context = () =>
{
#if NET45
#if NET451
AmbientDbContextStorageProvider.SetStorage(new LogicalCallContextStorage());
#else
AmbientDbContextStorageProvider.SetStorage(new AsyncLocalContextStorage());
Expand Down Expand Up @@ -48,7 +48,7 @@ class When_ambient_database_context_stack_has_one_ambient_database_context
{
Establish context = () =>
{
#if NET45
#if NET451
AmbientDbContextStorageProvider.SetStorage(new LogicalCallContextStorage());
#else
AmbientDbContextStorageProvider.SetStorage(new AsyncLocalContextStorage());
Expand Down Expand Up @@ -89,7 +89,7 @@ class When_ambient_database_context_stack_has_more_than_one_ambient_database_con
{
Establish context = () =>
{
#if NET45
#if NET451
AmbientDbContextStorageProvider.SetStorage(new LogicalCallContextStorage());
#else
AmbientDbContextStorageProvider.SetStorage(new AsyncLocalContextStorage());
Expand Down
Expand Up @@ -28,7 +28,7 @@ class When_getting_storage_after_it_has_been_set
{
Establish context = () =>
{
#if NET45
#if NET451
AmbientDbContextStorageProvider.SetStorage(new LogicalCallContextStorage());
#else
AmbientDbContextStorageProvider.SetStorage(new AsyncLocalContextStorage());
Expand Down

0 comments on commit 9c2c455

Please sign in to comment.