Raycynix.Extensions.Database.PostgreSql 3.1.0

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

Raycynix.Extensions.Database.PostgreSql

This package follows the shared version in Directory.Build.props. See CHANGELOG.md for release history.

PostgreSQL provider integration for Raycynix.Extensions.Database.

What It Provides

  • AddPostgreSql(...)
  • PostgreSqlOptions
  • PostgreSQL structured connection-string composition
  • PostgreSQL provider-specific validation
  • EF Core UseNpgsql(...) configuration with retries, command timeout, pooling, and migrations assembly support

The provider is selected by calling .AddPostgreSql(...).

Usage

builder.Services
    .AddRaycynixDatabase(builder.Configuration, options =>
    {
        options.UseMigrations = true;
        options.EnsureCreated = false;
    })
    .AddPostgreSql(postgreSql =>
    {
        postgreSql.IncludeErrorDetail = false;
        postgreSql.CommandTimeoutSeconds = 30;
    });

Table Schemas

Schema configuration is optional. Calling .AddPostgreSql() without schema options and omitting DatabaseSchema / EntitySchema leaves table names unqualified. PostgreSQL then uses its normal search_path resolution (typically the public schema). No schema name is required in configuration or code.

Set a default schema for all entities through registration:

builder.Services.AddRaycynixDatabase(builder.Configuration)
    .AddPostgreSql(options => options.DefaultSchema = "app");

Alternatively, set DatabaseOptions:PostgreSqlOptions:DefaultSchema in configuration. The default is null, which preserves PostgreSQL's normal schema resolution.

Apply DatabaseSchema to a GenericConfigurator<T>, alongside the optional table-name attribute:

using Raycynix.Extensions.Database.Abstractions.Attributes;
using Raycynix.Extensions.Database.Implementations;

[DatabaseTable("orders")]
[DatabaseSchema("sales")]
public sealed class OrderConfigurator : GenericConfigurator<Order>
{
    public override Type[] DependsOn => [];
}

This maps Order to sales.orders. For fluent configuration, import Raycynix.Extensions.Database.Infrastructure and configure the entity inside your configurator:

public override void Configure(ModelBuilder modelBuilder)
{
    ConfigureEntity(modelBuilder)
        .EntityName("orders")
        .EntitySchema("sales");
}

EntitySchema overrides the attribute and preserves the table name. EntityName also preserves the schema, so either chaining order works. These APIs live in the shared Database.Abstractions and Database packages, which the PostgreSQL package references.

Schema precedence is fluent entity mapping, then DatabaseSchema, then DefaultSchema, then the provider default. DefaultSchema applies modelBuilder.HasDefaultSchema(...) before entity configurators run. Without an explicit entity schema, EF Core uses that model default; otherwise table names remain unqualified and PostgreSQL resolves them through search_path. No public schema is forced. Pass null to EntitySchema to reset to the default. Empty or whitespace schema names are rejected. Use migrations or EnsureCreated to create the mapped schema and tables; these mapping APIs do not execute DDL themselves.

If a schema is selected from runtime configuration, include that value in your configurator's GetModelShapeCacheKey() override, just as for runtime table names. PostgreSqlOptions.DefaultSchema participates in the model cache key automatically, including design-time models. It is captured when the provider model configurator is first resolved; restart the application to change this application-wide setting.

DefaultSchema only changes model mappings. The __EFMigrationsHistory table keeps its standard provider location; existing migration history is not relocated. EF Core configures that table separately through MigrationsHistoryTable(...).

Configuration

{
  "DatabaseOptions": {
    "ConnectionOptions": {
      "Host": "localhost",
      "Port": 5432,
      "Name": "app",
      "Username": "app",
      "Password": "secret"
    },
    "UseMigrations": true,
    "EnsureCreated": false,
    "PostgreSqlOptions": {
      "Pooling": true,
      "MinimumPoolSize": 5,
      "MaximumPoolSize": 50,
      "CommandTimeoutSeconds": 30,
      "IncludeErrorDetail": false
    }
  }
}

When a raw ConnectionString is not supplied, structured PostgreSQL configuration requires Host, Name, and Username.

Logging

The provider emits optional Microsoft.Extensions.Logging diagnostics for validation, connection-string source selection, and EF Core provider configuration. Connection strings, usernames, and passwords are never logged.

Migrating From 2.x

  • Replace PostgreSqlConfiguration with PostgreSqlOptions.
  • Import it from Raycynix.Extensions.Database.PostgreSql.Options.
  • Rename the section from DatabaseConfiguration:PostgreSqlConfiguration to DatabaseOptions:PostgreSqlOptions.
  • Invalid pool ranges and negative command timeouts now fail during options validation.
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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Raycynix.Extensions 3.1.0. All packages inherit the shared version from Directory.Build.props. See https://github.com/raycynix/Raycynix.Extensions/blob/HEAD/src/Raycynix.Extensions.Database.PostgreSql/CHANGELOG.md for package-specific changes and https://github.com/raycynix/Raycynix.Extensions/blob/HEAD/CHANGELOG.md for the release overview.