KoreForge.Data
1.1.2
dotnet add package KoreForge.Data --version 1.1.2
NuGet\Install-Package KoreForge.Data -Version 1.1.2
<PackageReference Include="KoreForge.Data" Version="1.1.2" />
<PackageVersion Include="KoreForge.Data" Version="1.1.2" />
<PackageReference Include="KoreForge.Data" />
paket add KoreForge.Data --version 1.1.2
#r "nuget: KoreForge.Data, 1.1.2"
#:package KoreForge.Data@1.1.2
#addin nuget:?package=KoreForge.Data&version=1.1.2
#tool nuget:?package=KoreForge.Data&version=1.1.2
KoreForge.Data
Database-first EF Core data layer for KoreForge applications.
Overview
KoreForge.Data provides scaffolded EF Core DbContext and entity classes generated from existing SQL Server databases. The library follows a database-first approach — the database schema is the source of truth, and all entity code is produced by dotnet ef dbcontext scaffold.
Design Principles
- Database-first — schema is authoritative; EF migrations are not used
- Generated code is disposable — scaffold output can be deleted and recreated at any time
- Custom code survives regeneration — extensions live in partial classes outside the Generated/ folder
- Scripts are the entry point — developers use PowerShell scripts, not raw CLI commands
- Lookup tables, not enums — reference data lives in database tables with FK relationships
Package
| Package | NuGet |
|---|---|
KoreForge.Data |
Project Structure
KoreForge.Data/
├── config/
│ └── scaffold-config.json # Drives scaffolding — one entry per database
├── scr/
│ ├── scaffold-db.ps1 # Config-driven scaffold runner
│ └── AlertsDB-Notification-Schema.sql # DDL for the Notification schema
├── src/KoreForge.Data/
│ ├── AlertsDbContext.cs # Partial context extension (ns: KoreForge.Data)
│ ├── AlertsDbOptions.cs # Connection options (ns: KoreForge.Data)
│ ├── AlertsDbServiceCollectionExtensions.cs # DI registration (ns: KoreForge.Data)
│ └── Generated/ # Scaffold output — DO NOT EDIT
│ └── Alerts/ # AlertsDB database
│ ├── AlertsDbContext.cs # Generated context (ns: KoreForge.Data)
│ └── Notification/ # Notification schema entities
│ ├── Channel.cs # (ns: KoreForge.Data.Alerts.Notification)
│ ├── Priority.cs
│ ├── OutboxStatus.cs
│ ├── SendOutcome.cs
│ ├── NotificationOutbox.cs
│ ├── EmailPayload.cs
│ └── SmsPayload.cs
├── tst/KoreForge.Data.Tests/
├── scr/ # Build & release scripts
├── doc/ # Documentation
└── artifacts/ # NuGet package output
Quick Start
1. Install
dotnet add package KoreForge.Data
2. Register in Program.cs
using KoreForge.Data;
builder.Services.AddAlertsDb(opts =>
opts.ConnectionString = builder.Configuration.GetConnectionString("AlertsDB")!);
Or with a raw connection string:
builder.Services.AddAlertsDb("Server=.;Database=AlertsDB;...";
3. Inject and Use
using KoreForge.Data.Alerts.Notification;
public class NotificationService(AlertsDbContext db)
{
public async Task<List<NotificationOutbox>> GetPendingAsync(CancellationToken ct)
{
var pendingStatus = await db.OutboxStatus
.SingleAsync(s => s.Name == "Pending", ct);
return await db.NotificationOutbox
.Include(n => n.Channel)
.Include(n => n.Priority)
.Where(n => n.OutboxStatusId == pendingStatus.OutboxStatusId)
.OrderBy(n => n.CreatedAt)
.ToListAsync(ct);
}
}
Databases
AlertsDB — Notification Schema
| Table | Purpose |
|---|---|
Channel |
Lookup: Email, SMS, Push, InApp |
Priority |
Lookup: Low, Normal, High, Critical |
OutboxStatus |
Lookup: Pending, Processing, Sent, Failed, Cancelled |
SendOutcome |
Lookup: Success, HardBounce, SoftBounce, Rejected, Timeout, ProviderError |
NotificationOutbox |
Core outbox table with FK to all lookups |
EmailPayload |
Email-specific fields (from, cc, bcc, html flag) |
SmsPayload |
SMS-specific fields (from number, provider message id) |
All lookup values are database rows — no C# enums. FK relationships provide navigation properties automatically via scaffold.
Scaffolding
Prerequisites
- .NET 10 SDK
- SQL Server instance with the target database
- Run
dotnet tool restoreonce to installdotnet-ef
Running the Scaffold
.\scr\scaffold-db.ps1
This reads config/scaffold-config.json, cleans existing generated output, and runs dotnet ef dbcontext scaffold for each configured database.
To scaffold a single database:
.\scr\scaffold-db.ps1 -Database AlertsDB
Adding a New Database
- Run the SQL DDL against the target server
- Add a new entry to
config/scaffold-config.json - Run
.\scr\scaffold-db.ps1 -Database NewDbName - Add options class, DI registration, and empty partial context at
src/KoreForge.Data/project root - Set
namespaceandcontextNamespacein the config to keep "Generated" out of namespaces
Extending Generated Code
Generated files live in Generated/ and must never be edited by hand. To add custom behaviour, create partial classes at the project root (or any folder outside Generated/):
// src/KoreForge.Data/NotificationOutboxExtensions.cs
namespace KoreForge.Data.Alerts.Notification;
public partial class NotificationOutbox
{
public bool IsOverdue => OutboxStatus?.Name == "Pending"
&& CreatedAt < DateTimeOffset.UtcNow.AddHours(-1);
}
An empty partial AlertsDbContext is provided at src/KoreForge.Data/AlertsDbContext.cs for context-level extensions.
Namespace Convention
| Item | Namespace | Example |
|---|---|---|
| DbContext, Options, DI | {RootNs} |
KoreForge.Data |
| Entity models | {RootNs}.{DbName}.{Schema} |
KoreForge.Data.Alerts.Notification |
| Entity models (dbo schema) | {RootNs}.{DbName} |
KoreForge.Data.Alerts |
"Generated" never appears in a namespace — it is purely a folder for scaffold output.
Scripts
| Script | Purpose |
|---|---|
scr/scaffold-db.ps1 |
Config-driven scaffold runner |
scr/build-clean.ps1 |
Clean build outputs |
scr/build-rebuild.ps1 |
Force rebuild |
scr/build-test.ps1 |
Build + run tests |
scr/build-test-codecoverage.ps1 |
Build + test + coverage report |
scr/git-push.ps1 |
Add, commit, push |
scr/git-push-nuget.ps1 |
Tag and push for NuGet release |
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.EntityFrameworkCore (>= 10.0.0)
- Microsoft.EntityFrameworkCore.SqlServer (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- System.Security.Cryptography.Xml (>= 10.0.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.2 | 90 | 5/3/2026 |
| 1.1.0 | 87 | 4/30/2026 |
| 0.0.11-alpha | 95 | 4/30/2026 |
| 0.0.10-alpha | 83 | 4/30/2026 |
| 0.0.8-alpha | 96 | 4/26/2026 |
| 0.0.5-alpha | 105 | 3/23/2026 |