Skip to content

Commit

Permalink
Fix benchmarks for older EF Core versions
Browse files Browse the repository at this point in the history
To use old FromSql API
  • Loading branch information
roji committed Jul 3, 2019
1 parent 63f076b commit cd4695f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@
</ItemGroup>

<ItemGroup Condition=" '$(Configuration)' == 'Release22' ">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.4" />
</ItemGroup>

<ItemGroup Condition=" '$(Configuration)' == 'Release21' ">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.11" />
</ItemGroup>

<ItemGroup Condition=" '$(Configuration)' == 'Release20' ">
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.3" />
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release22' Or '$(Configuration)' == 'Release21' Or '$(Configuration)' == 'Release20' ">
<DefineConstants>$(DefineConstants);OLD_FROM_SQL</DefineConstants>
</PropertyGroup>

<ItemGroup>
<None Update="config.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@
</ItemGroup>

<ItemGroup Condition=" '$(Configuration)' == 'Release22' ">
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.4" />
</ItemGroup>

<ItemGroup Condition=" '$(Configuration)' == 'Release21' ">
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.11" />
</ItemGroup>

<ItemGroup Condition=" '$(Configuration)' == 'Release20' ">
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.0.3" />
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release22' Or '$(Configuration)' == 'Release21' Or '$(Configuration)' == 'Release20' ">
<DefineConstants>$(DefineConstants);OLD_FROM_SQL</DefineConstants>
</PropertyGroup>

<ItemGroup>
<None Update="AdventureWorks2014.db">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down
32 changes: 28 additions & 4 deletions benchmark/Shared.EFCore/Query/RawSqlQueryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ public virtual void CreateContext()
{
if (!string.IsNullOrEmpty(StoredProcedureCreationScript))
{
#if OLD_FROM_SQL
ctx.Database.ExecuteSqlCommand(StoredProcedureCreationScript);
#else
ctx.Database.ExecuteSqlRaw(StoredProcedureCreationScript);
#endif
}
});

Expand All @@ -58,8 +62,13 @@ public virtual void CleanupContext()
[Benchmark]
public virtual async Task SelectAll()
{
var sql = @"SELECT * FROM ""Products""";
var query = _context.Products
.FromSqlRaw(@"SELECT * FROM ""Products""")
#if OLD_FROM_SQL
.FromSql(sql)
#else
.FromSqlRaw(sql)
#endif
.ApplyTracking(Tracking);

if (Async)
Expand All @@ -75,8 +84,13 @@ public virtual async Task SelectAll()
[Benchmark]
public virtual async Task SelectParameterized()
{
var sql = @"SELECT * FROM ""Products"" WHERE ""CurrentPrice"" >= @p0 AND ""CurrentPrice"" <= @p1";
var query = _context.Products
.FromSqlRaw(@"SELECT * FROM ""Products"" WHERE ""CurrentPrice"" >= @p0 AND ""CurrentPrice"" <= @p1", 10, 14)
#if OLD_FROM_SQL
.FromSql(sql, 10, 14)
#else
.FromSqlRaw(sql, 10, 14)
#endif
.ApplyTracking(Tracking);

if (Async)
Expand All @@ -92,8 +106,13 @@ public virtual async Task SelectParameterized()
[Benchmark]
public virtual async Task SelectComposed()
{
var sql = @"SELECT * FROM ""Products""";
var query = _context.Products
.FromSqlRaw(@"SELECT * FROM ""Products""")
#if OLD_FROM_SQL
.FromSql(sql)
#else
.FromSqlRaw(sql)
#endif
.ApplyTracking(Tracking)
.Where(p => p.ActualStockLevel >= 2 && p.ActualStockLevel <= 6)
.OrderBy(p => p.Name);
Expand All @@ -111,8 +130,13 @@ public virtual async Task SelectComposed()
[Benchmark]
public virtual async Task StoredProcedure()
{
var sql = @"EXECUTE dbo.SearchProducts @p0, @p1";
var query = _context.Products
.FromSqlRaw(@"EXECUTE dbo.SearchProducts @p0, @p1", 10, 14)
#if OLD_FROM_SQL
.FromSql(sql, 10, 14)
#else
.FromSqlRaw(sql, 10, 14)
#endif
.ApplyTracking(Tracking);

if (Async)
Expand Down

0 comments on commit cd4695f

Please sign in to comment.