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

update Dapper and enable Dapper.AOT #1930

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion src/BenchmarksApps/TechEmpower/BlazorSSR/BlazorSSR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="Dapper" Version="2.1.21" />
<PackageReference Include="Dapper.AOT" Version="1.0.10" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="$(NpgsqlEntityFrameworkCorePostgreSQLVersion80)" />
</ItemGroup>
</Project>
5 changes: 4 additions & 1 deletion src/BenchmarksApps/TechEmpower/BlazorSSR/Database/Db.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
using Dapper;
using Npgsql;

[module: DapperAot] // enable AOT Dapper support project-wide
[module: CacheCommand] // reuse DbCommand instances when possible

namespace BlazorSSR.Database;

public sealed class Db : IAsyncDisposable
Expand All @@ -20,7 +23,7 @@ public Db(AppSettings appSettings)
public async Task<List<Fortune>> LoadFortunesRowsDapper()
{
await using var connection = _dataSource.CreateConnection();
var result = (await connection.QueryAsync<Fortune>($"SELECT id, message FROM fortune")).AsList();
var result = (await connection.QueryAsync<Fortune>("SELECT id, message FROM fortune")).AsList();

result.Add(new Fortune { Id = 0, Message = "Additional fortune added at request time." });
result.Sort(FortuneSortComparison);
Expand Down
11 changes: 11 additions & 0 deletions src/BenchmarksApps/TechEmpower/Minimal/Database/Db.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
using Dapper;
using Minimal.Models;

[module: DapperAot] // enable AOT Dapper support project-wide
[module: CacheCommand] // reuse DbCommand instances when possible

namespace Minimal.Database;

public class Db
Expand All @@ -28,6 +31,14 @@ public async Task<World> LoadSingleQueryRow()
return await ReadSingleRow(db);
}

// note that this QueryFirstOrDefaultAsync<struct> is unusual, hence DAP038
// see: https://aot.dapperlib.dev/rules/DAP038
//
// options:
// 0. leave it as-is
// 1. use QueryFirstAsync and eat the exception if no rows
// 2 use QueryFirstOrDefaultAsync<World?> which allows `null` to be expressed
[System.Diagnostics.CodeAnalysis.SuppressMessage("Library", "DAP038:Value-type single row 'OrDefault' usage", Justification = "Retain old behaviour for baseline")]
static Task<World> ReadSingleRow(DbConnection db)
{
return db.QueryFirstOrDefaultAsync<World>(
Expand Down
3 changes: 2 additions & 1 deletion src/BenchmarksApps/TechEmpower/Minimal/Minimal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

<ItemGroup>
<PackageReference Include="Npgsql" Version="$(NpgsqlVersion80)" />
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="Dapper" Version="2.1.21" />
<PackageReference Include="Dapper.AOT" Version="1.0.10" />
<PackageReference Include="RazorSlices" Version="0.6.2" />
</ItemGroup>

Expand Down
5 changes: 4 additions & 1 deletion src/BenchmarksApps/TechEmpower/Mvc/Database/DbDapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
using Mvc.Models;
using Npgsql;

[module: DapperAot] // enable AOT Dapper support project-wide
[module: CacheCommand] // reuse DbCommand instances when possible

namespace Mvc.Database;

public sealed class DbDapper
Expand All @@ -24,7 +27,7 @@ public DbDapper(AppSettings appSettings)
public async Task<List<Fortune>> LoadFortunesRowsDapper()
{
await using var connection = _dataSource.CreateConnection();
var result = (await connection.QueryAsync<Fortune>($"SELECT id, message FROM fortune")).AsList();
var result = (await connection.QueryAsync<Fortune>("SELECT id, message FROM fortune")).AsList();

result.Add(new Fortune { Id = 0, Message = "Additional fortune added at request time." });
result.Sort(FortuneSortComparison);
Expand Down
3 changes: 2 additions & 1 deletion src/BenchmarksApps/TechEmpower/Mvc/Mvc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="Dapper" Version="2.1.21" />
<PackageReference Include="Dapper.AOT" Version="1.0.10" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework) == 'net7.0'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
using Dapper;
using Npgsql;

[module: DapperAot] // enable AOT Dapper support project-wide
[module: CacheCommand] // reuse DbCommand instances when possible

namespace PlatformBenchmarks
{
public sealed class DapperDb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="Dapper" Version="2.1.21" />
<PackageReference Include="Dapper.AOT" Version="1.0.10" />
<PackageReference Include="RazorSlices" Version="0.6.2" />
</ItemGroup>

Expand Down
5 changes: 4 additions & 1 deletion src/BenchmarksApps/TechEmpower/RazorPages/Database/Db.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
using Npgsql;
using RazorPages.Models;

[module: DapperAot] // enable AOT Dapper support project-wide
[module: CacheCommand] // reuse DbCommand instances when possible

namespace RazorPages.Database;

public sealed class Db : IAsyncDisposable
Expand All @@ -24,7 +27,7 @@ public Db(AppSettings appSettings)
public async Task<List<Fortune>> LoadFortunesRowsDapper()
{
await using var connection = _dataSource.CreateConnection();
var result = (await connection.QueryAsync<Fortune>($"SELECT id, message FROM fortune")).AsList();
var result = (await connection.QueryAsync<Fortune>("SELECT id, message FROM fortune")).AsList();

result.Add(new Fortune { Id = 0, Message = "Additional fortune added at request time." });
result.Sort(FortuneSortComparison);
Expand Down
3 changes: 2 additions & 1 deletion src/BenchmarksApps/TechEmpower/RazorPages/RazorPages.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.123" />
<PackageReference Include="Dapper" Version="2.1.21" />
<PackageReference Include="Dapper.AOT" Version="1.0.10" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework) == 'net7.0'">
Expand Down
3 changes: 3 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<!-- Create database build configurations -->
<Configurations>Debug;Release;Debug_Database;Release_Database</Configurations>
<IsDatabase Condition="$(Configuration.EndsWith('_Database'))">true</IsDatabase>

<!-- enable AOT scenarios -->
<InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);Dapper.AOT</InterceptorsPreviewNamespaces>
</PropertyGroup>

</Project>