Installation
Add Socigy.OpenSource.DB to a .NET project, verify the source generator ran, and confirm every prerequisite is met.
Requirements
| Component | Minimum version | Notes |
|---|---|---|
| .NET | 10.0 | Required by the Roslyn 4.x incremental source generator |
| PostgreSQL | 14.0 | Currently the only supported database engine, required for gen_random_uuid() and similar |
| Npgsql | 6.0 | Transitive dependency when platform is "postgresql", needed for DateOnly and TimeOnly |
platform in socigy.json selects the target database engine. PostgreSQL is the only engine supported in this release. The tooling is built to add more engines later..csproj to avoid conflicts.Add the NuGet package
dotnet add package Socigy.OpenSource.DBOr reference it directly in your .csproj:
<ItemGroup>
<PackageReference Include="Socigy.OpenSource.DB" Version="0.3.2" />
</ItemGroup>What the package contains
Socigy.OpenSource.DB is a single reference that installs three components together:
- The base classes and interfaces shared across all DB operations.
- Manages the Npgsql connection lifecycle for you.
One package reference covers all three. Adding Socigy.OpenSource.DB is the only install step.
Make your class partial and build
The source generator augments your model classes by adding members in a companion generated file. Each class that maps to a table must be declared partial:
using Socigy.OpenSource.DB.Attributes;
[Table("users")]
public partial class User
{
[PrimaryKey, Default(DbDefaults.Guid.Random)]
public Guid Id { get; set; }
public string Username { get; set; } = "anonymous";
[Default(DbDefaults.Time.Now)]
public DateTime CreatedAt { get; set; }
}DbDefaults constants live in Socigy.OpenSource.DB.Attributes. A single using covers [Table], [Column], [PrimaryKey], [Default], and the rest. The one exception is [Nullable], which lives in Socigy.OpenSource.DB.Core.Attributes.Then build:
dotnet buildA successful build means the source generator ran. Inspect the output under obj/{Configuration}/net{version}/generated/Socigy.OpenSource.DB.SourceGenerator/ to find a User.g.cs file containing the generated Insert(), Query(), Update(), and Delete() methods.
obj/ to your .gitignore. Generated files are recreated on every build and should never be committed.Verify the generated output
To write the generated files to disk, add <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> to your .csproj:
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>After building, confirm the generated files exist:
ls obj/Debug/net10.0/generated/Socigy.OpenSource.DB.SourceGenerator/Socigy.OpenSource.DB.SourceGenerator.Program/You will see one .g.cs file per annotated class. The exact path varies by configuration (Debug, Release, DB_Migration) and target framework. Opening a generated file is a useful debugging technique: it shows exactly what SQL the builder produces.
In Visual Studio and JetBrains Rider, "Go to Definition" on a generated method navigates straight to the generated file.
Npgsql as a standalone reference
Because Npgsql is a transitive dependency, most projects do not need an explicit reference. If you call Npgsql APIs directly (for example NpgsqlDataSource or NpgsqlConnection), add it explicitly:
dotnet add package Npgsqlawait using var conn = new NpgsqlConnection(
"Host=localhost;Port=5432;Database=myapp;Username=postgres;Password=secret");
await conn.OpenAsync();Never hard-code credentials in source files. Read connection strings from environment variables or appsettings.json in production.
Alternative download: GitHub Packages
If you cannot reach NuGet.org, the package is also published to GitHub Packages. Add the GitHub NuGet source first:
dotnet nuget add source https://nuget.pkg.github.com/WailedParsley36/index.json \
--name github-socigy \
--username YOUR_GITHUB_USERNAME \
--password YOUR_GITHUB_PATThen install as normal:
dotnet add package Socigy.OpenSource.DB --source github-socigyread:packages scope at github.com/settings/tokens.Dependencies
The package declares two dependencies used by the diagnostics pipeline:
System.Diagnostics.DiagnosticSourcefor the OpenTelemetryActivitySourceandMeter.Microsoft.Extensions.Logging.AbstractionsforILoggersupport.
On .NET 6.0 and later these ship in the shared framework, so they add nothing to a typical web or console app. They are declared so non-framework consumers also resolve them. No action is required on your part.
Next steps
- Walk through a complete example in Quickstart.
- Build a real application end to end in the Tutorial.
- Understand the recommended directory layout in Project structure.
- Configure
socigy.jsonfor migrations and DI code generation in Configuration.