diff --git a/Dapper.Tests.Performance/Benchmarks.EntityFrameworkCore.cs b/Dapper.Tests.Performance/Benchmarks.EntityFrameworkCore.cs new file mode 100644 index 00000000..d306fae6 --- /dev/null +++ b/Dapper.Tests.Performance/Benchmarks.EntityFrameworkCore.cs @@ -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 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); + } + } +} \ No newline at end of file diff --git a/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj b/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj index 4292bd4d..3655b810 100644 --- a/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj +++ b/Dapper.Tests.Performance/Dapper.Tests.Performance.csproj @@ -17,6 +17,8 @@ + + diff --git a/Dapper.Tests.Performance/EntityFrameworkCore/EFCoreContext.cs b/Dapper.Tests.Performance/EntityFrameworkCore/EFCoreContext.cs new file mode 100644 index 00000000..e6fe1178 --- /dev/null +++ b/Dapper.Tests.Performance/EntityFrameworkCore/EFCoreContext.cs @@ -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 Posts { get; set; } + } +} \ No newline at end of file