Rask.Data 0.21.1-alpha.0.16

This is a prerelease version of Rask.Data.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Rask.Data --version 0.21.1-alpha.0.16
                    
NuGet\Install-Package Rask.Data -Version 0.21.1-alpha.0.16
                    
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="Rask.Data" Version="0.21.1-alpha.0.16" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Rask.Data" Version="0.21.1-alpha.0.16" />
                    
Directory.Packages.props
<PackageReference Include="Rask.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 Rask.Data --version 0.21.1-alpha.0.16
                    
#r "nuget: Rask.Data, 0.21.1-alpha.0.16"
                    
#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 Rask.Data@0.21.1-alpha.0.16
                    
#: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=Rask.Data&version=0.21.1-alpha.0.16&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Rask.Data&version=0.21.1-alpha.0.16&prerelease
                    
Install as a Cake Tool

Rask.Data

A data layer for Entity Framework Core apps with one goal: you declare models, and that is all. No DbContext class, no DbSet property, no IEntityTypeConfiguration, no registration — and no IDbContextFactory injected into everything that reads a row. Underneath it is ordinary EF Core, and Db.Current is the real DbContext whenever you want it.

  • Model<TId> — a base entity with Id, audit stamps (CreatedAt/UpdatedAt), and a domain-events buffer. A source generator finds every one of them and builds the model, so nothing is scanned or reflected and a trimmed publish cannot quietly drop a table.
  • The model type is its own DbSet — Product.Where(...), Product.FindAsync(id), Product.Add/Update/Remove(...), Product.CountAsync(). C# 14 static extension members, so an entity that compiles today has them. Reads are no-tracking by default and open no context until they run.
  • Db.Begin() — one short-lived ambient DbContext per unit of work, committed by a single SaveChangesAsync. Nesting joins rather than nests, so await entity.SaveAsync() inside a caller's transaction takes part in it instead of committing half of it.
  • Value objects (IValueObject) map as EF complex types, not owned entities; strongly-typed ids get a generated value converter with nothing declared; mapping rules live in a plain public static void Configure(EntityTypeBuilder<T>) on the model.
  • TestDatabase.StartAsync — a real database for a test in one line, so behaviour on a model is tested against the database it ships on rather than a mocked DbContext.
  • Opt-in markers — implement ISoftDeletable (adds DeletedAt) or IVersioned (adds a Version concurrency token) on your entity to turn on the behavior.
  • Three ISaveChangesInterceptors — auditing timestamps, transparent soft delete (a Remove becomes a DeletedAt stamp behind a global query filter), and after-commit domain-event publication through Rask.Cqrs.
  • BulkInsertAsync — the bulk insert EF Core leaves out (ExecuteUpdate/ExecuteDelete exist; inserts are out of its scope). Batched, with the change tracker cleared as it goes so memory stays flat.

Use

public sealed class Product : Model<Guid>, ISoftDeletable, IVersioned
{
    public string Name { get; private set; } = "";
    public DateTime? DeletedAt { get; private set; }
    public int Version { get; private set; }

    public static Product Create(string name) => new() { Id = Guid.NewGuid(), Name = name };
}

// read — no context in scope, nothing left open
var active = await Product.Where(p => p.DeletedAt == null).OrderBy(p => p.Name).ToListAsync();

// write — one transaction over everything it touches
await using var uow = Db.Begin();
Product.Add(Product.Create("Anvil"));
Product.Remove(discontinued);
await uow.SaveChangesAsync();

In a Rask app that is the whole of it — the host builds the model and points the ambient database at it. Elsewhere, name the context once and hand it over after the container is built:

builder.Services.AddRaskCqrs();
builder.Services.AddRaskData<AppDbContext>();
builder.Services.AddDbContextFactory<AppDbContext>((sp, o) => o
    .UseSqlite("Data Source=app.db")
    .AddInterceptors(sp.GetServices<ISaveChangesInterceptor>()));

var app = builder.Build();
Db.Configure(app.Services);

A class that does not derive from Model stays an ordinary EF Core entity: write your own context and configurations and use them exactly as before. Registering an IDbContextFactory<YourContext> is the whole of opting out at the app level.

db.Remove(product) now soft-deletes; deleted rows drop out of queries (use IgnoreQueryFilters() to restore); a save against a stale Version throws DbUpdateConcurrencyException; and any INotification raised on the entity is published after the change commits.

To load many rows at once — seeding, an import, a migration — await db.BulkInsertAsync(products) (or db.Products.BulkInsertAsync(...)) saves them in batches, clearing the change tracker between each so memory stays flat. The interceptors above still run for every row. Each batch commits on its own so a long import does not hold SQLite's only write lock end to end; o.SingleTransaction = true makes it all-or-nothing.

For the fastest load, o.SkipChangeTracking = true writes the rows with one prepared INSERT and no entity entries at all. It is opt-in because it runs no ISaveChangesInterceptor — the writer stamps the audit columns itself, but entities carrying domain events are rejected rather than silently losing them, and anything it cannot map faithfully throws and names the reason.

Non-overlapping ranges

A booking, a lease, a price valid for a period: two rows must not cover the same point. SQLite has no EXCLUDE constraint and a UNIQUE index only stops identical rows, so declare the rule on the model instead:

modelBuilder.Entity<Booking>()
    .HasNonOverlappingRange(x => x.StartsAt, x => x.EndsAt, partitionBy: x => x.RoomId);

Ranges are half-open ([lo, hi)), so 100-200 and 200-300 are neighbours rather than a conflict. With Rask.SQLite.EntityFrameworkCore's UseRaskSqlite(...), migrations emit the triggers that enforce it and a violating save throws RangeOverlapException. Enforcement lives in the database, so raw SQL is bound by it too.

Part of the Rask framework. MIT licensed.

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 (10)

Showing the top 5 NuGet packages that depend on Rask.Data:

Package Downloads
Rask.Server

The ASP.NET host for Rask, a full-stack .NET web framework, with every battery: database (SQLite, PostgreSQL or SQL Server, picked by Rask:Database:Provider), mediator and query cache, accounts, background jobs, transactional email, cache, file storage, outbox, operator dashboard, durable logs, Web Push, SQLite snapshots and continuous backup. Renders Rask components with live updates over a WebSocket. RaskApp.Create(args).Run<App>() is the whole Program.cs, and RaskApp.Create(args).Serve() the whole server of a WebAssembly client; app.Configure(c => c.Jobs.Off()) is how an app does without one. Depends on Rask, the shared core.

Rask.WebPush

Server-side Web Push for Rask: the browsers that subscribed, kept on the app's own database, and a send that reaches them — Push.Send(message) for everyone, .To(userId) for one person's devices — dropping subscriptions the push service says are gone. Signs VAPID (RFC 8292) and encrypts (RFC 8291 aes128gcm) with in-box System.Security.Cryptography, and maps the subscribe endpoints a WebAssembly client or SPA posts to. Push.Fake() for tests.

Rask.Mail

Durable transactional email for a Rask app, queued on its own database — no broker, no Redis. Compose an email (a Rask component rendered to HTML is the body), call `Mail.Send(email)`, and a background `MailProcessor` delivers it over SMTP (MailKit) — at-least-once, with exponential-backoff retries and dead-lettering, as the tenant it was queued for. Zero-config in development: logs or writes `.eml` files when no SMTP server is set. Server-side; pairs with EF Core.

Rask.Outbox

A transactional outbox for .NET on your app's own database (no broker, no Redis): give a domain-event handler `IDurableHandler<T>` and its row is written to an `OutboxMessage` table in the **same transaction** as the change that raised the event, so it is never lost and never fires for a rolled-back change. A background `OutboxProcessor` then runs each handler at-least-once with retries, woken by the save itself. Plain `IEventHandler<T>`s keep running in memory; each handler chooses. Server-side; pairs with Rask.Data and Rask.Cqrs.

Rask.Jobs

Durable background jobs for a Rask app, stored in its own database — no broker, no Redis. Enqueue a job (an `IJob`, dispatched to its Rask.Cqrs `ICommandHandler`) with `Jobs.Enqueue` and a background `JobProcessor` polls the table and runs it — at-least-once, with exponential-backoff retries. Supports delayed (run-at) jobs and durable interval-recurring jobs. A source generator registers each job type for reflection-free lookup. Server-side; pairs with Rask.Cqrs and EF Core.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.23.1-alpha.0.264 32 10/9/2026
0.23.1-alpha.0.248 40 10/9/2026
0.23.1-alpha.0.246 53 10/9/2026
0.23.1-alpha.0.245 52 10/9/2026
0.23.1-alpha.0.219 67 10/8/2026
0.23.1-alpha.0.206 82 10/7/2026
0.23.1-alpha.0.202 59 10/7/2026
0.23.1-alpha.0.200 71 10/7/2026
0.23.1-alpha.0.195 81 10/7/2026
0.23.1-alpha.0.193 75 10/7/2026
0.23.1-alpha.0.191 91 10/6/2026
0.23.1-alpha.0.185 86 10/6/2026
0.23.1-alpha.0.175 76 10/6/2026
0.23.1-alpha.0.167 78 10/6/2026
0.23.1-alpha.0.166 92 10/6/2026
0.23.1-alpha.0.159 80 10/6/2026
0.23.1-alpha.0.154 82 10/6/2026
0.23.1-alpha.0.153 86 10/6/2026
0.23.0 249 9/18/2026
0.21.1-alpha.0.16 77 9/11/2026
Loading failed