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

Enable DapperAOT #2079

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 build/dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
<MicrosoftIISTestingVersion90>9.0.0-*</MicrosoftIISTestingVersion90>
<MicrosoftIISTestingVersion100>10.0.0-*</MicrosoftIISTestingVersion100>

<DapperVersion>2.1.35</DapperVersion>
<DapperVersion>2.1.66</DapperVersion>
<DapperAotVersion>1.0.48</DapperAotVersion>
<RazorSlicesVersion>0.8.1</RazorSlicesVersion>
<SystemCommandLineVersion>2.0.0-beta4.22272.1</SystemCommandLineVersion>
<MicrosoftCrankEventSourcesVersion>0.2.0-alpha.24114.2</MicrosoftCrankEventSourcesVersion>
Expand Down
1 change: 1 addition & 0 deletions src/Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

<ItemGroup>
<PackageReference Include="Dapper" Version="$(DapperVersion)" />
<PackageReference Include="Dapper.AOT" Version="$(DapperAotVersion)" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
Expand Down
3 changes: 3 additions & 0 deletions src/Benchmarks/Data/DapperDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Benchmarks.Data
{
[DapperAot, CacheCommand, StrictTypes]
public class DapperDb : IDb
{
private static readonly Comparison<World> WorldSortComparison = (a, b) => a.Id.CompareTo(b.Id);
Expand All @@ -38,6 +39,7 @@ public async Task<World> LoadSingleQueryRow()
}
}

[QueryColumns("id", "randomnumber")]
Task<World> ReadSingleRow(DbConnection db)
{
return db.QueryFirstOrDefaultAsync<World>(
Expand Down Expand Up @@ -92,6 +94,7 @@ public async Task<World[]> LoadMultipleUpdatesRows(int count)

}

[QueryColumns("id", "message")]
public async Task<IEnumerable<FortuneUtf16>> LoadFortunesRows()
{
List<FortuneUtf16> result;
Expand Down
3 changes: 2 additions & 1 deletion src/Benchmarks/Data/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;
using Dapper;

namespace Benchmarks.Data
{
Expand All @@ -13,7 +14,7 @@ public class World
public int Id { get; set; }

[IgnoreDataMember]
[NotMapped]
[NotMapped, DbValue(Ignore = true)]
public int _Id { get; set; }

[Column("randomnumber")]
Expand Down
1 change: 1 addition & 0 deletions src/BenchmarksApps/TechEmpower/BlazorSSR/BlazorSSR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<PackageReference Include="Dapper" Version="$(DapperVersion)" />
<PackageReference Include="Dapper.AOT" Version="$(DapperAotVersion)" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="$(NpgsqlEntityFrameworkCorePostgreSQLVersion80)" />
<PackageReference Include="Npgsql" Version="$(NpgsqlVersion80)" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/BenchmarksApps/TechEmpower/BlazorSSR/Database/Db.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public Db(AppSettings appSettings)
_dataSource = new NpgsqlSlimDataSourceBuilder(appSettings.ConnectionString).Build();
}

[DapperAot, CacheCommand, StrictTypes, QueryColumns("id", "message")]
public async Task<List<Fortune>> LoadFortunesRowsDapper()
{
await using var connection = _dataSource.CreateConnection();
Expand Down
3 changes: 3 additions & 0 deletions src/BenchmarksApps/TechEmpower/Minimal/Database/Db.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Minimal.Database;

[DapperAot, CacheCommand, StrictTypes]
public class Db
{
private static readonly Comparison<Fortune> FortuneSortComparison = (a, b) => string.CompareOrdinal(a.Message, b.Message);
Expand All @@ -28,9 +29,10 @@
return await ReadSingleRow(db);
}

[QueryColumns("id", "randomnumber")]
static Task<World> ReadSingleRow(DbConnection db)
{
return db.QueryFirstOrDefaultAsync<World>(

Check warning on line 35 in src/BenchmarksApps/TechEmpower/Minimal/Database/Db.cs

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-latest)

Type 'World' is a value-type; it will not be trivial to identify missing rows from QueryFirstOrDefaultAsync (https://aot.dapperlib.dev/rules/DAP038)
"SELECT id, randomnumber FROM world WHERE id = @Id",
new { Id = Random.Shared.Next(1, 10001) });
}
Expand Down Expand Up @@ -83,6 +85,7 @@
return results;
}

[QueryColumns("id", "message")]
public async Task<List<Fortune>> LoadFortunesRows()
{
List<Fortune> result;
Expand Down
1 change: 1 addition & 0 deletions src/BenchmarksApps/TechEmpower/Minimal/Minimal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ItemGroup>
<PackageReference Include="Npgsql" Version="$(NpgsqlVersion80)" />
<PackageReference Include="Dapper" Version="$(DapperVersion)" />
<PackageReference Include="Dapper.AOT" Version="$(DapperAotVersion)" />
<PackageReference Include="RazorSlices" Version="$(RazorSlicesVersion)" />
</ItemGroup>

Expand Down
1 change: 1 addition & 0 deletions src/BenchmarksApps/TechEmpower/Mvc/Database/DbDapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public DbDapper(AppSettings appSettings)
#endif
}

[DapperAot, CacheCommand, StrictTypes, QueryColumns("id", "message")]
public async Task<List<Fortune>> LoadFortunesRowsDapper()
{
await using var connection = _dataSource.CreateConnection();
Expand Down
1 change: 1 addition & 0 deletions src/BenchmarksApps/TechEmpower/Mvc/Mvc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<ItemGroup>
<PackageReference Include="Dapper" Version="$(DapperVersion)" />
<PackageReference Include="Dapper.AOT" Version="$(DapperAotVersion)" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework) == 'net8.0'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public sealed class DapperDb
public DapperDb(AppSettings appSettings)
=> _connectionString = appSettings.ConnectionString;

[DapperAot, CacheCommand, StrictTypes, QueryColumns("id", "message")]
public async Task<List<FortuneUtf16>> LoadFortunesRows()
{
List<FortuneUtf16> result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

<ItemGroup>
<PackageReference Include="Dapper" Version="$(DapperVersion)" />
<PackageReference Include="Dapper.AOT" Version="$(DapperAotVersion)" />
<PackageReference Include="RazorSlices" Version="$(RazorSlicesVersion)" />
</ItemGroup>

Expand Down
1 change: 1 addition & 0 deletions src/BenchmarksApps/TechEmpower/RazorPages/Database/Db.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public Db(AppSettings appSettings)
#endif
}

[DapperAot, CacheCommand, StrictTypes, QueryColumns("id", "message")]
public async Task<List<Fortune>> LoadFortunesRowsDapper()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to have both DapperAOT and Dapper variants? Aren't we losing "plain" Dapper testing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to double everything, and I don't think we need to retain both - the key thing here is "what approach would the user be using?", and DapperAOT === Dapper from that angle.

{
await using var connection = _dataSource.CreateConnection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<PackageReference Include="Dapper" Version="$(DapperVersion)" />
<PackageReference Include="Dapper.AOT" Version="$(DapperAotVersion)" />
</ItemGroup>

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

<!-- enable interceptors language feature for Dapper globally (this by itself doesn't add AOT) -->
<InterceptorsNamespaces>$(InterceptorsNamespaces);Dapper.AOT</InterceptorsNamespaces>
<!-- for parity on down-level SDKs -->
<InterceptorsPreviewNamespaces>$(InterceptorsNamespaces)</InterceptorsPreviewNamespaces>
</PropertyGroup>

</Project>
Loading