mcpField
E
entity-framework

entity-framework

github.com/stuartf303Data & databases42 installs
Repository

About entity-framework

A skill for developers working with EF Core, documenting Sorcha’s EF Core 9+ and PostgreSQL data-access patterns, including repositories, soft deletes, and migrations.

Key features

  1. 01PostgreSQL DbContext setup
  2. 02Generic and specialized repositories
  3. 03Soft-delete query filters
  4. 04Create and apply migrations
  5. 05JSONB and bulk updates

Use cases

  1. 01Configure databases for Sorcha services
  2. 02Build repositories with optional eager loading
  3. 03Manage soft-deleted records
  4. 04Create and apply database migrations

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/stuartf303/sorcha --skill entity-framework

After installing, type/entity-frameworkin Claude Code to confirm it loaded.

Bundled filesreferences/patterns.mdreferences/workflows.md

Details

From the project README

Entity Framework Core Skill

Sorcha uses EF Core 9+ with PostgreSQL (Npgsql) as the primary relational data store. The codebase implements a layered repository pattern with generic and specialized repositories, soft delete via query filters, and automatic migrations on startup.

Quick Start

Register DbContext with PostgreSQL
// src/Common/Sorcha.Storage.EFCore/Extensions/EFCoreServiceExtensions.cs
services.AddDbContext<WalletDbContext>((sp, options) =>
{
    var dataSource = sp.GetRequiredService<NpgsqlDataSource>();
    options.UseNpgsql(dataSource, npgsql =>
    {
        npgsql.EnableRetryOnFailure(maxRetryCount: 10, maxRetryDelay: TimeSpan.FromSeconds(30), errorCodesToAdd: null);
        npgsql.MigrationsHistoryTable("__EFMigrationsHistory", "wallet");
    });
});
Create a Migration
# From project directory containing DbContext
dotnet ef migrations add InitialSchema --project src/Common/Sorcha.Wallet.Core --startup-project src/Services/Sorcha.Wallet.Service
Apply Migrations Programmatically
// Startup pattern used in Sorcha services
var pending = await dbContext.Database.GetPendingMigrationsAsync();
if (pending.Any())
    await dbContext.Database.MigrateAsync();

Key Concepts

ConceptUsageExample
DbContextSchema definition + change trackingWalletDbContext, TenantDbContext
RepositoryData access abstractionEFCoreRepository<T, TId, TContext>
Soft DeleteQuery filter on DeletedAt.HasQueryFilter(e => e.DeletedAt == null)
JSONBPostgreSQL JSON columns.HasColumnType("jsonb")
ExecuteUpdateBulk updates without loadingExecuteUpdateAsync(s => s.SetProperty(...))

Common Patterns

Repository with Optional Eager Loading
// src/Common/Sorcha.Wallet.Core/Repositories/EfCoreWalletRepository.cs
public async Task<WalletEntity?> GetByAddressAsync(string address, bool includeAddresses = false)
{
    IQueryable<WalletEntity> query = _context.Wallets;
    
    if (includeAddresses)
        query = query.Include(w => w.Addresses);
    
    return await query.AsNoTracking().FirstOrDefaultAsync(w => w.Address == address);
}
Soft Delete with Filter Bypass
// Bypass query filter for admin operations
var deleted = await _context.Wallets
    .IgnoreQueryFilters()
    .FirstOrDefaultAsync(w => w.Address == address);

See Also

  • patterns - DbContext configuration, entity mapping, query optimization
  • workflows - Migration commands, testing patterns, deployment

Related Skills

  • See the postgresql skill for connection configuration and PostgreSQL-specific features
  • See the aspire skill for service registration and health checks
  • See the xunit skill for testing DbContext with InMemory provider

Documentation Resources

Fetch latest EF Core documentation with Context7.

Library ID: /dotnet/entityframework.docs

Recommended Queries:

  • "DbContext pooling configuration dependency injection"
  • "migrations code-first apply production deployment"
  • "query filters soft delete global filters"
  • "bulk operations ExecuteUpdate ExecuteDelete"

Comments

Markdown supported