KoreForge.Data 1.1.2

dotnet add package KoreForge.Data --version 1.1.2
                    
NuGet\Install-Package KoreForge.Data -Version 1.1.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="KoreForge.Data" Version="1.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="KoreForge.Data" Version="1.1.2" />
                    
Directory.Packages.props
<PackageReference Include="KoreForge.Data" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add KoreForge.Data --version 1.1.2
                    
#r "nuget: KoreForge.Data, 1.1.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package KoreForge.Data@1.1.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=KoreForge.Data&version=1.1.2
                    
Install as a Cake Addin
#tool nuget:?package=KoreForge.Data&version=1.1.2
                    
Install as a Cake Tool

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

  1. Database-first — schema is authoritative; EF migrations are not used
  2. Generated code is disposable — scaffold output can be deleted and recreated at any time
  3. Custom code survives regeneration — extensions live in partial classes outside the Generated/ folder
  4. Scripts are the entry point — developers use PowerShell scripts, not raw CLI commands
  5. Lookup tables, not enums — reference data lives in database tables with FK relationships

Package

Package NuGet
KoreForge.Data NuGet

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 restore once to install dotnet-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

  1. Run the SQL DDL against the target server
  2. Add a new entry to config/scaffold-config.json
  3. Run .\scr\scaffold-db.ps1 -Database NewDbName
  4. Add options class, DI registration, and empty partial context at src/KoreForge.Data/ project root
  5. Set namespace and contextNamespace in 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

MIT

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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