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

Added EntityFrameworkCore performance tests #778

Merged
merged 1 commit into from
Jun 2, 2017
Merged
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
44 changes: 44 additions & 0 deletions Dapper.Tests.Performance/Benchmarks.EntityFrameworkCore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using BenchmarkDotNet.Attributes;
using Dapper.Tests.Performance.Linq2Sql;
using Microsoft.EntityFrameworkCore;
using System;
using System.Data.Linq;
using System.Linq;

namespace Dapper.Tests.Performance
{
public class EFCoreBenchmarks : BenchmarkBase
{
private EntityFrameworkCore.EFCoreContext Context;
private static readonly Func<DataClassesDataContext, int, Linq2Sql.Post> compiledQuery =
CompiledQuery.Compile((DataClassesDataContext ctx, int id) => ctx.Posts.First(p => p.Id == id));

[Setup]
public void Setup()
{
BaseSetup();
Context = new EntityFrameworkCore.EFCoreContext(_connection.ConnectionString);
}

[Benchmark(Description = "Normal")]
public Post Normal()
{
Step();
return Context.Posts.First(p => p.Id == i);
}

[Benchmark(Description = "SqlQuery")]
public Post SqlQuery()
{
Step();
return Context.Posts.FromSql("select * from Posts where Id = {0}", i).First();
}

[Benchmark(Description = "No Tracking")]
public Post NoTracking()
{
Step();
return Context.Posts.AsNoTracking().First(p => p.Id == i);
}
}
}
2 changes: 2 additions & 0 deletions Dapper.Tests.Performance/Dapper.Tests.Performance.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<!--<PackageReference Include="BLToolkit" Version="4.3.6" />-->
<PackageReference Include="EntityFramework" Version="6.1.3" />
<PackageReference Include="FirebirdSql.Data.FirebirdClient" Version="5.9.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.2" />
Copy link
Member

Choose a reason for hiding this comment

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

Since Microsoft.EntityFrameworkCore.SqlServer ultimately depends on Microsoft.EntityFrameworkCore (via .Relational), this line isn't needed in the new project system:

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.2" />

<PackageReference Include="Microsoft.SqlServer.Compact" Version="4.0.8876.1" />
<PackageReference Include="Microsoft.SqlServer.Types" Version="14.0.314.76" />
<PackageReference Include="MySql.Data" Version="7.0.7-m61" />
Expand Down
18 changes: 18 additions & 0 deletions Dapper.Tests.Performance/EntityFrameworkCore/EFCoreContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Microsoft.EntityFrameworkCore;

namespace Dapper.Tests.Performance.EntityFrameworkCore
{
public class EFCoreContext : DbContext
{
private readonly string _connectionString;

public EFCoreContext(string connectionString)
{
_connectionString = connectionString;
}

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder.UseSqlServer(_connectionString);

public DbSet<Post> Posts { get; set; }
}
}