Skip to content

Instantly share code, notes, and snippets.

@j0nimost
Last active May 14, 2020 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j0nimost/6ecae720d6859f46bef33ff901f252a5 to your computer and use it in GitHub Desktop.
Save j0nimost/6ecae720d6859f46bef33ff901f252a5 to your computer and use it in GitHub Desktop.
public class ACMContext: DbContext
{
public ACMContext(DbContextOptions<ACMContext> options)
:base(options)
{
}
public virtual DbSet<ACMPreauthList> PreauthLists { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<ACMPreauthList>().HasNoKey().ToView("case_management_preauth_list")
.Property(x => x.InvoiceAmount)
.HasColumnType("decimal(18,2)");
base.OnModelCreating(modelBuilder);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;
namespace BenchmarkSQL.Models
{
public class ACMPreauthList
{
public Int32 InvoiceId { get; set; }
public Int32 TreatmentId { get; set; }
public string InvoiceReference { get; set; }
public Decimal InvoiceAmount { get; set; }
public DateTime TreatmentDate { get; set; }
public string InvoiceStatus { get; set; }
public Int32 BeneficiaryId { get; set; }
public string FirstName { get; set; }
public string Surname { get; set; }
public string CompanyName { get; set; }
public string LengthOfStay { get; set; }
public DateTime DischargeDate { get; set; }
public DateTime AdmissionDate { get; set; }
public string CapturedBy { get; set; }
public string ConditionDescription { get; set; }
public Int32 AffectedSystem { get; set; }
public string AdmissionStatus { get; set; }
public string PolicyHolderName { get; set; }
public string ClientType { get; set; }
public string DOB { get; set; }
public Int32 Age { get; set; }
public string Gender { get; set; }
public string AffectedSystemName { get; set; }
public DateTime EffectiveDate { get; set; }
public Int32 PolicyHolderId { get; set; }
public string BrokerName { get; set; }
public string InvoiceBenefit { get; set; }
}
}
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Running;
using BenchmarkSQL.DAL;
using BenchmarkSQL.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace BenchmarkSQL
{
public class ACMTester
{
private DAL.ACMContext con;
public IEnumerable<ACMPreauthList> GetACMPreauthFromSQLToEnum(long beneficiaryId)
{
return this.con.PreauthLists.FromSqlRaw<ACMPreauthList>("SELECT * FROM case_management_preauth_list WHERE BeneficiaryId={0}", beneficiaryId).ToList();
}
public IEnumerable<ACMPreauthList> GetACMPreauthFromSetToEnum(long beneficiaryId)
{
return this.con.Set<ACMPreauthList>().Where(x => x.BeneficiaryId == beneficiaryId).ToList();
}
[GlobalSetup]
public void GlobalSetup()
{
var services = Program.ConfigureServices();
var serviceProvider = services.BuildServiceProvider();
this.con = serviceProvider.GetService<ACMContext>();
}
[Benchmark]
public void FromSQLToEnum()
{
GetACMPreauthFromSQLToEnum(1192843);
}
[Benchmark]
public void FromSetToEnum()
{
GetACMPreauthFromSetToEnum(1192843);
}
}
public class Program
{
static void Main(string[] args)
{
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
}
public static IServiceCollection ConfigureServices()
{
IServiceCollection services = new ServiceCollection();
services.AddDbContext<DAL.ACMContext>(db =>
{
db.UseSqlServer("SQLconn",
opt => opt.CommandTimeout((int)TimeSpan.FromMinutes(20).TotalSeconds));
});
return services;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment