MagicCSharp.Data.Postgres 1.0.2

dotnet add package MagicCSharp.Data.Postgres --version 1.0.2
                    
NuGet\Install-Package MagicCSharp.Data.Postgres -Version 1.0.2
                    
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="MagicCSharp.Data.Postgres" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MagicCSharp.Data.Postgres" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="MagicCSharp.Data.Postgres" />
                    
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 MagicCSharp.Data.Postgres --version 1.0.2
                    
#r "nuget: MagicCSharp.Data.Postgres, 1.0.2"
                    
#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 MagicCSharp.Data.Postgres@1.0.2
                    
#: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=MagicCSharp.Data.Postgres&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=MagicCSharp.Data.Postgres&version=1.0.2
                    
Install as a Cake Tool

MagicCSharp.Data.Postgres

PostgreSQL wiring for MagicCSharp.Data.EntityFramework: a pooled context factory read from configuration that fails at startup rather than on the first query, a design-time factory for dotnet ef, and an interceptor for the one timestamptz mistake that only ever shows up on a developer's machine.

Add it to the data project alongside MagicCSharp.Data.EntityFramework when the database is Postgres.

dotnet add package MagicCSharp.Data.Postgres

Registration

builder.Services.AddPostgresDbContextFactory<MagicShopContext>(builder.Configuration);

Reads DB_HOST, DB_PORT, DB_NAME, DB_USER and DB_PASSWORD. Each is required — a missing one throws rather than quietly defaulting to localhost. Set a different ConfigPrefix on PostgresConnectionOptions to point a second context at another database (VECTOR_DB_HOST, and so on).

Registers a pooled factory, which is what makes the repositories' context-per-operation cheap: pooling reuses the context and its internal service provider rather than rebuilding the model each time. Opens one connection during registration, so a wrong host or password fails at startup instead of on the first request that needs the database; set DB_VERIFY_CONNECTION=false where that is wrong — a test that swaps every repository out, or a container that starts before its database.

Pool sizes, timeouts and retry live in PostgresConnectionOptions. Size MaxPoolSize against the server's limit divided by the number of instances you run, or a rolling deploy will exhaust the server.

Two hooks for the provider, also on PostgresConnectionOptions: ConfigureDataSource for an Npgsql type plugin such as pgvector's UseVector(), and ConfigureNpgsql for the options inside UseNpgsql. A query that Includes two collections at once throws rather than multiplying the rows — that is almost never what was meant, and throwing turns a silent performance cliff into a fix-once error.

Migrations

public class MagicShopContextFactory() : MagicDbContextFactory<MagicShopContext>("shop");

dotnet ef builds the context without your DI container, so it needs this. Without one it falls back to booting the whole host just to read a connection string. The argument is the default database name; host, port, user and password default to a local Postgres and are overridden by the same DB_* variables.

The UTC interceptor

Registered for you. It normalizes every DateTimeOffset command parameter to UTC.

MagicDbContext already does that on save, but save only sees entities. A Where comparing a timestamp, an ExecuteUpdate, an ExecuteDelete and raw SQL all bind parameters without going near the change tracker. Npgsql requires offset zero for a timestamptz parameter, so one of those carrying a local offset throws at bind time — on a developer's machine, and not in CI, because CI runs in UTC.

The whole picture, and the optional repository layout: github.com/MagicDoorInc/MagicCSharp. MIT.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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 (1)

Showing the top 1 NuGet packages that depend on MagicCSharp.Data.Postgres:

Package Downloads
MagicCSharp.Testing.Database

Repository integration testing for MagicCSharp against a real PostgreSQL in Testcontainers: one container shared across the suite, a logical database per test class, schema created once, and tables truncated between tests. Separate from MagicCSharp.Testing because it needs Docker, xUnit and Npgsql.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 190 9/24/2026
1.0.1 103 9/24/2026
1.0.0 98 9/23/2026