Rask.Data 0.21.1-alpha.0.33

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.33
                    
NuGet\Install-Package Rask.Data -Version 0.21.1-alpha.0.33
                    
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.33" />
                    
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.33" />
                    
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.33
                    
#r "nuget: Rask.Data, 0.21.1-alpha.0.33"
                    
#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.33
                    
#: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.33&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Rask.Data&version=0.21.1-alpha.0.33&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. On a provider that emits no such DDL — a plain UseSqlite, or any other — the rule would be silently ignored, so AddRaskData<TContext>() refuses to boot instead, naming the entity and the call that enforces it.

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 `IMail.SendAsync`, 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.SQLite.EntityFrameworkCore

The Entity Framework Core integration for Rask.SQLite: `UseRaskSqlite(...)`, a drop-in replacement for `UseSqlite` that also registers a `ConnectionOpened` interceptor applying the production pragma set (WAL, `synchronous=NORMAL`, `foreign_keys=ON`, a `busy_timeout`, `mmap_size`, `journal_size_limit`) to every connection the context opens, and full-text search on SQLite FTS5 for Rask.Data's `HasFullTextSearch` — migrations create the index and its sync triggers, and `Search(text)` translates to a ranked query; `UseRaskFullTextSearch()` adds that search alone to a plain `UseSqlite`, such as a browser app's; and JSON path indexes for Rask.Data's `HasJsonIndex`. Split out from Rask.SQLite so apps that only need the raw `Microsoft.Data.Sqlite` path (or run on mobile/AOT) don't pull in Entity Framework Core.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.23.1-alpha.0.122 0 10/1/2026
0.23.1-alpha.0.121 0 10/1/2026
0.23.1-alpha.0.117 0 10/1/2026
0.23.1-alpha.0.116 38 9/30/2026
0.23.1-alpha.0.115 52 9/30/2026
0.23.1-alpha.0.114 49 9/30/2026
0.23.1-alpha.0.113 6 10/1/2026
0.23.1-alpha.0.110 7 10/1/2026
0.23.1-alpha.0.109 67 9/30/2026
0.23.1-alpha.0.108 44 9/30/2026
0.23.1-alpha.0.106 46 9/30/2026
0.23.1-alpha.0.103 51 9/29/2026
0.23.1-alpha.0.100 49 9/29/2026
0.23.1-alpha.0.98 66 9/29/2026
0.23.1-alpha.0.96 56 9/29/2026
0.23.1-alpha.0.95 57 9/29/2026
0.23.1-alpha.0.92 56 9/29/2026
0.23.1-alpha.0.90 62 9/29/2026
0.23.0 245 9/18/2026
0.21.1-alpha.0.33 74 9/11/2026
Loading failed