This repository is a .NET library (distributed as NuGet packages) that adds a second-level query cache to Entity Framework Core applications. In production, it registers a DbCommandInterceptor that intercepts every EF Core database command: SELECT queries are converted into a cache key by hashing the SQL text, parameters, and connection string; on a cache hit, the stored result set is replayed through a custom DbDataReader implementation so EF Core never touches the database; on a miss, the query executes normally and the result is serialized into a row/column format for storage. Cache invalidation is automatic — when SaveChanges/SaveChangesAsync runs, the interceptor parses the SQL to identify affected tables and evicts all cache entries that depend on them. The architecture is a clean provider pattern. The core package (EFCoreSecondLevelCacheInterceptor) defines the interceptor, cache-key generation, SQL table extraction, and the IEFCacheServiceProvider abstraction, while separate companion packages implement backends: MemoryCache, StackExchange.Redis (with custom MessagePack serialization), FusionCache, .NET HybridCache, EasyCaching.Core, and CacheManager.Core. Public entry points are the AddEFSecondLevelCache() DI extension and the Cacheable()/NotCacheable() query extensions, with fluent configuration for expiration modes (absolute/sliding/never), per-query or global policies, and lock modes for concurrency. The codebase is actively maintained (last commit 2026-09-19, zero open issues, dependabot-clean), multi-targets .NET from net462/netstandard2.0 through net10.0, and enforces strict quality gates: TreatWarningsAsErrors, SonarAnalyzer, Meziantou analyzers, and heap-allocation analyzers. Test coverage is extensive — unit tests for key generation, SQL parsing, and data-reader reconstruction, plus integration tests across providers and issue-specific repro projects. Notable craftsmanship includes a hand-written XxHash64 unsafe implementation for fast key hashing, a DbDataReader reconstruction layer that transparently replays cached rows to EF Core, and a SQL table-name extraction processor driving invalidation. Primary risks are the heavy conditional compilation across 10+ target frameworks, SQL parsing heuristics that can miss edge cases (CTEs, subqueries, quoted identifiers), and reliance on third-party cache libraries — CacheManager.Core is explicitly unmaintained upstream. Bulk operations (ExecuteUpdate/ExecuteDelete) bypass the interceptor and require manual invalidation.
This repository provides a .NET library for performing high-performance bulk operations (insert, update, delete, merge, match) with Entity Framework Core and SQL Server. It extends DbContext with extension methods that leverage SqlBulkCopy and temporary tables to minimize database round-trips when processing large datasets. The library supports synchronous and asynchronous APIs, handles complex EF Core features (owned types, complex types, JSON properties, discriminators), and includes a fluent builder pattern for configuring operations. The architecture centers around extension methods for DbContext and a ConnectionContext abstraction for lower-level SQL operations. Key internal components include a property access cache for performance, sequential GUID generation for index-friendly keys, and a table mapping system to customize entity-to-table mappings. The library implements bulk operations by creating temporary tables, using SqlBulkCopy for efficient data loading, and then executing set-based SQL operations (INSERT, UPDATE, DELETE, MERGE) to synchronize with the target tables. Notable reusable components include the PropertiesCache, which compiles and caches property accessors to eliminate reflection overhead, and the SequentialGuidGenerator, which creates database-optimized GUIDs. The library is actively maintained, targets recent .NET versions, and includes a comprehensive test suite and benchmark projects validating performance improvements over standard EF Core operations.