mirror of
https://github.com/DapperLib/Dapper.git
synced 2026-10-17 05:12:13 +08:00
Added EntityFrameworkCore performance tests (#778)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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" />
|
||||
<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" />
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user