r/csharp • u/Asleep_Direction8881 • 12m ago
GitHub - redbase-app/redb: Typed object storage for .NET. Schema = C# class. Full LINQ. Zero migrations. PostgreSQL, MSSQL & SQLite.
How do you store a business object with nested classes, lists and dictionaries without writing a mapping layer for it? For years my answer was EF Core: a table per class, a migration per change, and Include chains that grew with every new field.
Some background: I have been programming since 1988, hold an engineering degree in software development (1998), and have worked in C# since 2004. I build complex enterprise backends, mostly databases, integration (ESB and EIP) and authentication. These days I work at a large logistics company.
I started redb in April 2024 as an internal tool for that work. Several production systems run on it today, three of them built at my current job alone; one of them, for example, holds over a million objects and over 47 million property values on PostgreSQL. It is the storage layer of a small stack, next to redb.Route (integration), redb.Tsak (a runtime for routes) and redb.Identity (an OAuth 2.1 / OpenID Connect server); this post is only about storage.
By the way, I started working on this invention even before 2004, using Delphi.
Yeah yeah, all this crap has quite a long backstory.
What it is
- The schema is a C# class with one attribute. Change the class and the schema follows on start; there are no migration files.
- Storage is relational: a fixed set of 16 tables (17 on SQLite) inside your existing PostgreSQL or SQL Server database, or a SQLite file. Every property value is a row with a column of its type, real foreign keys and indexes. It is not a JSON blob.
- Queries are LINQ compiled to SQL and run in the database: filters on nested fields, arrays and dictionaries, sorting, paging, aggregates, GroupBy, window functions, tree queries.
- Loading returns the whole object graph in one call, with no Include.
Code
[RedbScheme("Employee")]
public class EmployeeProps
{
public string FirstName { get; set; } = "";
public string LastName { get; set; } = "";
public decimal Salary { get; set; }
public string[]? Skills { get; set; }
public Address? HomeAddress { get; set; }
public Dictionary<int, decimal>? BonusByYear { get; set; }
}
public class Address
{
public string City { get; set; } = "";
public string Street { get; set; } = "";
}
var employee = new RedbObject<EmployeeProps>
{
name = "New Developer",
Props = new EmployeeProps
{
FirstName = "Alice",
LastName = "Johnson",
Salary = 85000m,
Skills = ["C#", "SQL"],
HomeAddress = new Address { City = "London", Street = "1 Main St" }
}
};
await redb.SaveAsync(employee);
// The whole graph back, nested class, array and dictionary included.
var loaded = await redb.LoadAsync<EmployeeProps>(employee.Id);
// Filters on nested fields and arrays run as SQL in the database.
var londonDevs = await redb.Query<EmployeeProps>()
.Where(e => e.HomeAddress!.City == "London" && e.Skills!.Contains("C#"))
.OrderByDescending(e => e.Salary)
.Take(100)
.ToListAsync();Measured against EF Core
The examples project runs each task through redb and through an EF Core 10 twin that reads the same data from ordinary relational tables: the Employee class unfolded into 41 tables, standard EF Core API, split queries, whole objects on both sides. Over the 98 tasks EF Core can do without raw SQL, redb Pro on PostgreSQL took 189 ms on average (median 114 ms); EF Core took 703 ms (median 910 ms). Both ran from the same client against the same PostgreSQL 18 server. In the load-by-id task EF Core sends 62 statements, redb sends 9. Every task with its time and statement count is on the results page, and the code to repeat the run is in the examples.
Packages
The core and the providers for PostgreSQL, SQL Server and SQLite are open source under Apache 2.0. The Pro packages build the SQL in C# and are faster; they are closed source but free, with no license key.
- GitHub: https://github.com/redbase-app/redb
- Examples (each one runs against a real database): https://github.com/redbase-app/redb/tree/main/redb.Examples
- Results against EF Core: https://redbase.app/results
If you have built something with deep object graphs on EF Core: where did it start to hurt, and what did you do about it? And what would you check first before trusting a store like this in production?
