Skip to content

Instantly share code, notes, and snippets.

View davepcallan's full-sized avatar

Dave Callan davepcallan

View GitHub Profile
@davepcallan
davepcallan / SlowQueryInterceptor.cs
Last active November 25, 2025 15:54
Finding slow queries with Entity Framework Interceptors
using Microsoft.EntityFrameworkCore.Diagnostics;
using System.Data.Common;
namespace EntityFrameworkExamples;
public class SlowQueryInterceptor(ILogger<SlowQueryInterceptor> logger) : DbCommandInterceptor
{
private const int _slowQueryThresholdInMilliseconds = 5; //from config
public override DbDataReader ReaderExecuted(
@davepcallan
davepcallan / EntityFrameworkBatchSizeBenchmark.cs
Created November 25, 2025 15:49
Sample benchmark to test different Entity Framework batch sizes with the SQL Server provider
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Reports;
using Microsoft.EntityFrameworkCore;
using System.Threading.Tasks;
namespace EntityFrameworkBenchmarks;
[Config(typeof(Config))]
@davepcallan
davepcallan / tracking-v-notracking.cs
Created November 25, 2025 15:42
Entity Framework Tracking v No-Tracking example BenchmarkDotNet benchmark
using System;
using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet.Attributes;
using Microsoft.EntityFrameworkCore;
namespace Benchmarks;
[MemoryDiagnoser]
public class QueryTrackingBehavior
@davepcallan
davepcallan / Program.cs
Created January 3, 2025 08:42
.NET Rate limiting simple examples
using Microsoft.AspNetCore.RateLimiting;
using System.Threading.RateLimiting;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRateLimiter(options =>
{
// 1. Fixed Window Limiter (20 requests per 2 minutes)
// -----------------------------------------------
// |----------------- 2 min -----------------|
@davepcallan
davepcallan / HybridCacheQuerying.mmd
Created January 27, 2025 04:47
HybridCache Mermaid sequence diagrams for querying HybridCache and Invalidating it in multi-instance scenario
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@davepcallan
davepcallan / stringConcatenationDotnet8.cs
Last active July 8, 2025 12:03
.NET 8 simple string concatenation benchmarks
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
using System;
using System.Text;
namespace Benchmarks
{
@davepcallan
davepcallan / EFQueryFlow.mmd
Created February 10, 2025 18:14
Entity Framework query flow sequence diagram
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@davepcallan
davepcallan / GlobalExceptionHandler.cs
Last active March 2, 2025 13:40
ASP.NET 8 Global exception handling with IExceptionHandler example
using Microsoft.AspNetCore.Diagnostics;
namespace Samples;
public class GlobalExceptionHandler(ILogger<GlobalExceptionHandler> logger) : IExceptionHandler
{
public ValueTask<bool> TryHandleAsync(
HttpContext httpContext,
Exception exception,
CancellationToken cancellationToken)
@davepcallan
davepcallan / SBvSJBenchmarks.cs
Created February 16, 2025 15:59
StringBuilder v different String.Join overloads
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
using System;
using System.Collections.Generic;
using System.Text;
namespace Benchmarks
@davepcallan
davepcallan / StringConcatSimple.cs
Last active February 16, 2025 15:23
.NET 9 Simple String concatenation
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
using System.Runtime.CompilerServices;
using System.Text;
namespace Benchmarks
{