Skip to content
Open
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 Dapper/SqlMapper.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ private static async Task<IEnumerable<TReturn>> MultiMapAsync<TFirst, TSecond, T
using var cmd = command.TrySetupAsyncCommand(cnn, info.ParamReader);
using var reader = await ExecuteReaderWithFlagsFallbackAsync(cmd, wasClosed, CommandBehavior.SequentialAccess | CommandBehavior.SingleResult, command.CancellationToken).ConfigureAwait(false);
if (!command.Buffered) wasClosed = false; // handing back open reader; rely on command-behavior
var results = MultiMapImpl<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TReturn>(null, CommandDefinition.ForCallback(command.Parameters, command.Flags), map, splitOn, reader, identity, true);
var results = MultiMapImpl<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TReturn>(null, CommandDefinition.ForCallback(command.Parameters, command.Flags), map, splitOn, reader, identity, true, info);
return command.Buffered ? results.ToList() : results;
}
finally
Expand Down Expand Up @@ -988,7 +988,7 @@ private static async Task<IEnumerable<TReturn>> MultiMapAsync<TReturn>(this IDbC
if (wasClosed) await cnn.TryOpenAsync(command.CancellationToken).ConfigureAwait(false);
using var cmd = command.TrySetupAsyncCommand(cnn, info.ParamReader);
using var reader = await ExecuteReaderWithFlagsFallbackAsync(cmd, wasClosed, CommandBehavior.SequentialAccess | CommandBehavior.SingleResult, command.CancellationToken).ConfigureAwait(false);
var results = MultiMapImpl(null, default, types, map, splitOn, reader, identity, true);
var results = MultiMapImpl(null, default, types, map, splitOn, reader, identity, true, info);
return command.Buffered ? results.ToList() : results;
}
finally
Expand Down
8 changes: 4 additions & 4 deletions Dapper/SqlMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1584,11 +1584,11 @@ private static IEnumerable<TReturn> MultiMap<TFirst, TSecond, TThird, TFourth, T
return buffered ? results.ToList() : results;
}

private static IEnumerable<TReturn> MultiMapImpl<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TReturn>(this IDbConnection? cnn, CommandDefinition command, Delegate map, string splitOn, DbDataReader? reader, Identity? identity, bool finalize)
private static IEnumerable<TReturn> MultiMapImpl<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TReturn>(this IDbConnection? cnn, CommandDefinition command, Delegate map, string splitOn, DbDataReader? reader, Identity? identity, bool finalize, CacheInfo? cacheInfo = null)
{
object? param = command.Parameters;
identity ??= new Identity<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh>(command.CommandText, command.CommandTypeDirect, cnn!, typeof(TFirst), param?.GetType());
CacheInfo cinfo = GetCacheInfo(identity, param, command.AddToCache);
CacheInfo cinfo = cacheInfo ?? GetCacheInfo(identity, param, command.AddToCache);

IDbCommand? ownedCommand = null;
DbDataReader? ownedReader = null;
Expand Down Expand Up @@ -1650,7 +1650,7 @@ private static CommandBehavior GetBehavior(bool close, CommandBehavior @default)
return (close ? (@default | CommandBehavior.CloseConnection) : @default) & Settings.AllowedCommandBehaviors;
}

private static IEnumerable<TReturn> MultiMapImpl<TReturn>(this IDbConnection? cnn, CommandDefinition command, Type[] types, Func<object[], TReturn> map, string splitOn, DbDataReader? reader, Identity? identity, bool finalize)
private static IEnumerable<TReturn> MultiMapImpl<TReturn>(this IDbConnection? cnn, CommandDefinition command, Type[] types, Func<object[], TReturn> map, string splitOn, DbDataReader? reader, Identity? identity, bool finalize, CacheInfo? cacheInfo = null)
{
if (types.Length < 1)
{
Expand All @@ -1659,7 +1659,7 @@ private static IEnumerable<TReturn> MultiMapImpl<TReturn>(this IDbConnection? cn

object? param = command.Parameters;
identity ??= new IdentityWithTypes(command.CommandText, command.CommandTypeDirect, cnn!, types[0], param?.GetType(), types);
CacheInfo cinfo = GetCacheInfo(identity, param, command.AddToCache);
CacheInfo cinfo = cacheInfo ?? GetCacheInfo(identity, param, command.AddToCache);

IDbCommand? ownedCommand = null;
DbDataReader? ownedReader = null;
Expand Down
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<PackageVersion Include="RepoDb.SqlServer" Version="1.13.1" />
<PackageVersion Include="ServiceStack.OrmLite.SqlServer" Version="10.0.6" />
<PackageVersion Include="Snowflake.Data" Version="5.5.0" />
<PackageVersion Include="pengdows.crud.fakeDb" Version="2.0.5" />
<PackageVersion Include="SqlMarshal" Version="0.5.0" />
<PackageVersion Include="SubSonic" Version="3.0.0.4" />
<PackageVersion Include="Susanoo.SqlServer" Version="1.2.4.2" />
Expand Down
1 change: 1 addition & 0 deletions tests/Dapper.Tests/Dapper.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'net481'">
<PackageReference Include="pengdows.crud.fakeDb" />
<PackageReference Include="Npgsql" />
<PackageReference Include="Snowflake.Data" />
</ItemGroup>
Expand Down
42 changes: 42 additions & 0 deletions tests/Dapper.Tests/FakeDbTests.Issue2240.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#if !NET481
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using pengdows.crud.fakeDb;
using Xunit;

namespace Dapper.Tests;

public sealed class FakeDbIssue2240Tests
{
[Fact]
public async Task FirstAsyncMultiMapExecutionDoesNotRecordSyntheticCacheHit()
{
SqlMapper.PurgeQueryCache();
using var connection = new fakeDbConnection(new FakeDataStore());
connection.EnqueueReaderResult(new[]
{
new Dictionary<string, object?>
{
["A"] = 1,
["B"] = 2,
["C"] = 3,
},
});
connection.Open();

await connection.QueryAsync<First, Second, Third, int>(
"select 1 as A, 2 as B, 3 as C",
(a, b, c) => a.A + b.B + c.C,
splitOn: "B,C");

var cached = SqlMapper.GetCachedSQL().ToList();
Assert.NotEmpty(cached);
Assert.Equal(0, cached.Single().Item3);
}

private sealed class First { public int A { get; set; } }
private sealed class Second { public int B { get; set; } }
private sealed class Third { public int C { get; set; } }
}
#endif