mirror of
https://github.com/zoriya/EntityFrameworkCore.Projectables.git
synced 2026-05-18 01:10:23 +00:00
Added compatiblity mode
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using EntityFrameworkCore.Projectables.Extensions;
|
||||
using EntityFrameworkCore.Projectables.Infrastructure;
|
||||
|
||||
namespace EntityFrameworkCore.Projectables.Benchmarks.Helpers
|
||||
{
|
||||
class TestDbContext : DbContext
|
||||
{
|
||||
readonly bool _useProjectables;
|
||||
readonly bool _useFullCompatibiltyMode;
|
||||
|
||||
public TestDbContext(bool useProjectables, bool useFullCompatibiltyMode = true)
|
||||
{
|
||||
_useProjectables = useProjectables;
|
||||
_useFullCompatibiltyMode = useFullCompatibiltyMode;
|
||||
}
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.UseSqlServer("Server=(localdb)\\MSSQLLocalDB;Database=ReadmeSample;Trusted_Connection=True");
|
||||
|
||||
if (_useProjectables)
|
||||
{
|
||||
optionsBuilder.UseProjectables(projectableOptions => {
|
||||
projectableOptions.CompatibilityMode(_useFullCompatibiltyMode ? CompatibilityMode.Full : CompatibilityMode.Limited);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public DbSet<TestEntity> Entities => Set<TestEntity>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EntityFrameworkCore.Projectables.Benchmarks.Helpers
|
||||
{
|
||||
public class TestEntity
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Projectable]
|
||||
public int IdPlus1 => Id + 1;
|
||||
}
|
||||
}
|
||||
@@ -1,40 +1,16 @@
|
||||
using System;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using EntityFrameworkCore.Projectables.Benchmarks.Helpers;
|
||||
using EntityFrameworkCore.Projectables.Extensions;
|
||||
using EntityFrameworkCore.Projectables.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace EntityFrameworkCore.Projectables.Benchmarks
|
||||
{
|
||||
public class PlainOverhead
|
||||
{
|
||||
class TestEntity
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
class TestDbContext : DbContext
|
||||
{
|
||||
readonly bool _useProjectables;
|
||||
|
||||
public TestDbContext(bool useProjectables)
|
||||
{
|
||||
_useProjectables = useProjectables;
|
||||
}
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.UseSqlServer("Server=(localdb)\\MSSQLLocalDB;Database=ReadmeSample;Trusted_Connection=True");
|
||||
|
||||
if (_useProjectables)
|
||||
{
|
||||
optionsBuilder.UseProjectables();
|
||||
}
|
||||
}
|
||||
|
||||
public DbSet<TestEntity> Entities => Set<TestEntity>();
|
||||
}
|
||||
|
||||
[Benchmark(Baseline = true)]
|
||||
public void WithoutProjectables()
|
||||
{
|
||||
@@ -47,7 +23,7 @@ namespace EntityFrameworkCore.Projectables.Benchmarks
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void WithProjectables()
|
||||
public void WithProjectablesWithFullCompatibility()
|
||||
{
|
||||
using var dbContext = new TestDbContext(true);
|
||||
|
||||
@@ -57,5 +33,17 @@ namespace EntityFrameworkCore.Projectables.Benchmarks
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Benchmark]
|
||||
public void WithProjectablesWithLimitedCompatibility()
|
||||
{
|
||||
using var dbContext = new TestDbContext(true, false);
|
||||
|
||||
for (int i = 0; i < 10000; i++)
|
||||
{
|
||||
dbContext.Entities.Select(x => x.Id).ToQueryString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,43 +1,15 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using EntityFrameworkCore.Projectables.Benchmarks.Helpers;
|
||||
using EntityFrameworkCore.Projectables.Extensions;
|
||||
using EntityFrameworkCore.Projectables.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace EntityFrameworkCore.Projectables.Benchmarks
|
||||
{
|
||||
public class ProjectableProperties
|
||||
{
|
||||
public class TestEntity
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Projectable]
|
||||
public int IdPlus1 => Id + 1;
|
||||
}
|
||||
|
||||
class TestDbContext : DbContext
|
||||
{
|
||||
readonly bool _useProjectables;
|
||||
|
||||
public TestDbContext(bool useProjectables)
|
||||
{
|
||||
_useProjectables = useProjectables;
|
||||
}
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.UseSqlServer("Server=(localdb)\\MSSQLLocalDB;Database=ReadmeSample;Trusted_Connection=True");
|
||||
|
||||
if (_useProjectables)
|
||||
{
|
||||
optionsBuilder.UseProjectables();
|
||||
}
|
||||
}
|
||||
|
||||
public DbSet<TestEntity> Entities => Set<TestEntity>();
|
||||
}
|
||||
|
||||
[Benchmark(Baseline = true)]
|
||||
public void WithoutProjectables()
|
||||
{
|
||||
@@ -50,7 +22,7 @@ namespace EntityFrameworkCore.Projectables.Benchmarks
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void WithProjectables()
|
||||
public void WithProjectablesWithFullCompatibility()
|
||||
{
|
||||
using var dbContext = new TestDbContext(true);
|
||||
|
||||
@@ -60,5 +32,15 @@ namespace EntityFrameworkCore.Projectables.Benchmarks
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void WithProjectablesWithLimitedCompatibility()
|
||||
{
|
||||
using var dbContext = new TestDbContext(true, false);
|
||||
|
||||
for (int i = 0; i < 10000; i++)
|
||||
{
|
||||
dbContext.Entities.Select(x => x.IdPlus1).ToQueryString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user