Loading...
Loading...
Handles Entity Framework Core database access, migrations, and repository patterns for PostgreSQL. Use when: Creating DbContext classes, writing migrations, implementing repositories, configuring entity relationships, or optimizing database queries.
npx skill4agent add stuartf303/sorcha entity-framework// 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");
});
});# From project directory containing DbContext
dotnet ef migrations add InitialSchema --project src/Common/Sorcha.Wallet.Core --startup-project src/Services/Sorcha.Wallet.Service// Startup pattern used in Sorcha services
var pending = await dbContext.Database.GetPendingMigrationsAsync();
if (pending.Any())
await dbContext.Database.MigrateAsync();| Concept | Usage | Example |
|---|---|---|
| DbContext | Schema definition + change tracking | |
| Repository | Data access abstraction | |
| Soft Delete | Query filter on | |
| JSONB | PostgreSQL JSON columns | |
| ExecuteUpdate | Bulk updates without 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);
}// Bypass query filter for admin operations
var deleted = await _context.Wallets
.IgnoreQueryFilters()
.FirstOrDefaultAsync(w => w.Address == address);Fetch latest EF Core documentation with Context7.
/dotnet/entityframework.docs