Rask.Data 0.21.1-alpha.0.72

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.72
                    
NuGet\Install-Package Rask.Data -Version 0.21.1-alpha.0.72
                    
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.72" />
                    
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.72" />
                    
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.72
                    
#r "nuget: Rask.Data, 0.21.1-alpha.0.72"
                    
#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.72
                    
#: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.72&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Rask.Data&version=0.21.1-alpha.0.72&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 to read a row or save a form. Underneath it is ordinary EF Core, and anything richer than a create, an update or a delete is EF Core exactly as you know it.

  • Model<TId> — a base entity with Id 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.
  • Reads off the typeProduct.Where(...), Product.FindAsync(id), Product.CountAsync(), Product.AsQueryable(). C# 14 static extension members, so an entity that compiles today has them. Every read is untracked and opens and disposes its own context, which is what makes them safe on a page that lives as long as a browser's socket. AsQueryable() is a standard IQueryable<T> that opens a context per execution — hand it to a data grid and it sorts and pages in the database.
  • A generated ProductModel for forms — a settable copy of each entity's mapped properties, with its DataAnnotations and Version carried and the key left out, so Form.Model(model) validates by the entity's own rules. It is the whitelist a create or update writes from: [SkipModel] keeps a property off it.
  • Hints, not rules — build warnings with lightbulb fixes point out a public setter or field on a model or value object (RASK084) and an entity exposing a mutable collection of entities (RASK085). Public setters are allowed; the warnings never fail a build that does not ask them to.
  • Writes off the typeProduct.CreateAsync(model) (or a built entity), Product.UpdateAsync(id, model), Product.UpdateAsync(id, p => …) and Product.DeleteAsync(id). A form's values go through the generated model; values that do not come from the form go in an optional p => …; the id is always the caller's, never the form's; an IVersioned edit refuses a stale save. Each takes an optional DbContext to join a caller's transaction. The interceptors stamp, version, soft-delete and publish as for any save — and anything richer is plain EF Core through IDbContextFactory<TContext>.
  • 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 ITimestamped (adds CreatedAt/UpdatedAt), ISoftDeletable (adds DeletedAt) or IVersioned (a Version concurrency token) on your entity to turn on the behavior.
  • Three ISaveChangesInterceptors — auditing timestamps, transparent soft delete (a delete 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
{
    private Product() { }

    [Required, MaxLength(200)]
    public string Name { get; private set; } = "";
    public int Version { get; private set; }
}

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

// write — off the type too; the form model is the whitelist, the id is yours
var product = await Product.CreateAsync(model);
await Product.UpdateAsync(product.Id, edit);   // only changed columns; a stale Version throws
await Product.DeleteAsync(product.Id);         // soft delete

// anything richer — plain EF Core, one context, one transaction (the writes above join it with db: db)
await using var db = await contexts.CreateDbContextAsync(ct);
var order = await db.Set<Order>().FirstAsync(o => o.Id == orderId, ct);
order.Cancel(DateTime.UtcNow);
await db.SaveChangesAsync(ct);

In a Rask app that is the whole of it — the host builds the model and points the model surface 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.

A delete — db.Remove(product) — soft-deletes an ISoftDeletable; 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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

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

Package Downloads
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. 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.

Rask.Outbox

A transactional outbox for Rask.Data entities: domain events marked `IOutboxEvent` are written to an `OutboxMessage` table in the **same transaction** as the change that raised them (so an event is never lost and never fires for a rolled-back change), then a background `OutboxProcessor` polls the table and publishes them through Rask.Cqrs — at-least-once, crash-safe delivery, all on the app's own database (no broker, no Redis). A source generator registers each event type for reflection-free lookup. Server-side; pairs with Rask.Data.

Rask

The one reference a Rask application needs, server or browser. On a server target (net10.0 or net11.0) it brings the ASP.NET host plus every battery — database (SQLite, PostgreSQL or SQL Server, picked by Rask:Database:Provider), mediator, background jobs, transactional email, cache, file storage, outbox, operator dashboard, durable logs, Web Push, and SQLite snapshots and continuous backup — with RaskApp.Create(args) as the entry point. On a browser target it brings the WebAssembly host, the source-generated mediator, the query cache and remote dispatch. Everything referenced is wired and on; app.Configure(c => c.Jobs.Off()) is how an app does without one. Reference Rask.Server for a lean host with no database.

Rask.Auth.Api

Register, sign in and sign out as JSON endpoints, for an ASP.NET Core app that renders no Rask components — a TypeScript SPA host or a meta-framework host, where the front end owns the UI. Accounts are the app's own User aggregate (PBKDF2 or bcrypt password hashing, passkeys, one revocable session row per device, sign-in throttling) and are exposed at /api/auth, with email confirmation and password reset through the app's own mail queue and optional bearer tokens. The first account to register becomes the admin. This is the host-neutral half of Rask.Auth: no components, no renderer, no Rask.Core. Add Rask.Auth instead when the app IS a Rask app and wants the built-in sign-in pages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.22.1-alpha.0.15 0 9/16/2026
0.22.1-alpha.0.14 0 9/16/2026
0.22.1-alpha.0.13 0 9/16/2026
0.22.1-alpha.0.12 0 9/16/2026
0.22.1-alpha.0.9 0 9/16/2026
0.22.1-alpha.0.8 0 9/16/2026
0.22.1-alpha.0.7 0 9/16/2026
0.22.1-alpha.0.6 0 9/16/2026
0.22.1-alpha.0.4 0 9/16/2026
0.22.1-alpha.0.3 0 9/16/2026
0.22.1-alpha.0.2 0 9/16/2026
0.22.1-alpha.0.1 0 9/16/2026
0.22.0 0 9/16/2026
0.21.1-alpha.0.88 0 9/16/2026
0.21.1-alpha.0.87 31 9/15/2026
0.21.1-alpha.0.83 36 9/15/2026
0.21.1-alpha.0.81 32 9/15/2026
0.21.1-alpha.0.80 32 9/15/2026
0.21.1-alpha.0.78 36 9/15/2026
0.21.1-alpha.0.72 32 9/15/2026
Loading failed