/DB
Socigy.OpenSource.DB

Annotate once. Query forever.

Socigy.OpenSource.DB is a Roslyn source generator that reads your annotated C# classes at build time and emits a fully typed PostgreSQL data layer — INSERT, SELECT, UPDATE, DELETE, JOINs, set operations, and migrations — without a single line of boilerplate. Define your schema in C#, build, and every query method is already there waiting for you.

version
v0.1.82
channel
stable
runtime
C#
license
MIT-NC
Other versions
Available on
Quickstart

From zero to a typed query in minutes.

Follow the steps to get DB wired up. Everything you need is in one package.

  1. 01Add the NuGet package.
    dotnet add package Socigy.OpenSource.DB
  2. 02Annotate a C# class as a table. Make it partial so the generator can augment it.
    [Table("users")]
    public partial class User
    {
        [PrimaryKey, Default(DbDefaults.Guid.Random)]
        public Guid Id { get; set; }
    
        // C# initializer → DEFAULT 'anonymous' in DDL
        public string Username { get; set; } = "anonymous";
    
        [Default(DbDefaults.Time.Now)]
        public DateTime CreatedAt { get; set; }
    }
  3. 03Build once — the generator emits Insert(), Query(), Update(), and Delete() methods. Then use them.
    // INSERT — skip [Default] columns so the database generates them
    var user = new User { Username = "alice" };
    await user.Insert()
        .WithConnection(conn)
        .ExcludeAutoFields()
        .ExecuteAsync();
    
    // SELECT with a typed WHERE predicate
    await foreach (var u in User.Query(x => x.Username == "alice")
        .WithConnection(conn).ExecuteAsync())
    {
        Console.WriteLine($"{u.Id}: {u.Username}");
    }
using Socigy.OpenSource.DB.Core.Attributes;
using Socigy.OpenSource.DB.Core.Values;

[Table("users")]
public partial class User
{
    [PrimaryKey, Default(DbDefaults.Guid.Random)]
    public Guid Id { get; set; }

    public string Username { get; set; } = "anonymous";

    public string? Email { get; set; }

    [Default(DbDefaults.Time.Now)]
    public DateTime CreatedAt { get; set; }
}