Skip to main content

Provides helpers for logging database activity within Entity Framework Core

Total Downloads
23.7K
23,688
Published
Jun 30, 2025
1y ago

Get Started

dotnet add package Shane32.EfCoreHelpers --version 1.0.0
ProductVersions
.NET
net8.0

README

Shane32.EfCoreHelpers

NuGet

This library contains a set of helper classes and methods to facilitate testing of code based on Entity Framework Core.

Sample use with SQLite EF Core database:


public class TestDbContext : AppDbContext
{
    private readonly StringBuilder _logBuilder = new();

    public TestDbContext(SqliteConnection connection) : base(new DbContextOptionsBuilder<AppDbContext>().UseSqlite(connection).Options)
    {
    }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        base.OnConfiguring(optionsBuilder);
        optionsBuilder.LogToStringBuilder(_logBuilder, enableSensitiveDataLogging: true);
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.PrepForSqlite();
    }

    public void ResetDbTrace(bool resetChangeTracker = true)
    {
        if (resetChangeTracker)
            ChangeTracker.Clear();
        _logBuilder.Clear();
    }

    public string DbTrace => _logBuilder.ToString();
}

Credits

Glory to Jehovah, Lord of Lords and King of Kings, creator of Heaven and Earth, who through his Son Jesus Christ, has reedemed me to become a child of God. -Shane32

Downloads by Version

Not enough data for chart

Depended On By

Find packages that declare this package as a dependency. NuGet does not provide a reverse-dependency endpoint, so candidates are checked on demand.

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

Compatibility metadata lists 1 target framework; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.