AuroraScienceHub.Framework.EntityFramework.NpgSql 9.0.4

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package AuroraScienceHub.Framework.EntityFramework.NpgSql --version 9.0.4
                    
NuGet\Install-Package AuroraScienceHub.Framework.EntityFramework.NpgSql -Version 9.0.4
                    
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="AuroraScienceHub.Framework.EntityFramework.NpgSql" Version="9.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AuroraScienceHub.Framework.EntityFramework.NpgSql" Version="9.0.4" />
                    
Directory.Packages.props
<PackageReference Include="AuroraScienceHub.Framework.EntityFramework.NpgSql" />
                    
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 AuroraScienceHub.Framework.EntityFramework.NpgSql --version 9.0.4
                    
#r "nuget: AuroraScienceHub.Framework.EntityFramework.NpgSql, 9.0.4"
                    
#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 AuroraScienceHub.Framework.EntityFramework.NpgSql@9.0.4
                    
#: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=AuroraScienceHub.Framework.EntityFramework.NpgSql&version=9.0.4
                    
Install as a Cake Addin
#tool nuget:?package=AuroraScienceHub.Framework.EntityFramework.NpgSql&version=9.0.4
                    
Install as a Cake Tool

AuroraScienceHub.Framework.EntityFramework.NpgSql

PostgreSQL-specific extensions for Entity Framework Core including DbContext factories and optimized configurations.

Overview

Provides PostgreSQL-specific implementations for Entity Framework Core, including design-time DbContext factories for migrations and PostGIS spatial support.

Key Features

  • DbContext Factories - Design-time factories for EF migrations
  • PostGIS Support - Spatial data types and operations
  • PostgreSQL Conventions - Database naming and configuration
  • Performance Optimizations - PostgreSQL-specific optimizations

Installation

dotnet add package AuroraScienceHub.Framework.EntityFramework.NpgSql

Usage

DbContext Factory

// 1. Define connection options
public class DatabaseOptions : IConnectionOptions
{
    public static string OptionKey => "Database";
    public string Host { get; set; } = "localhost";
    public int Port { get; set; } = 5432;
    public string Database { get; set; } = string.Empty;
    public string Username { get; set; } = string.Empty;
    public string Password { get; set; } = string.Empty;

    public string GetConnectionString()
    {
        return $"Host={Host};Port={Port};Database={Database};Username={Username};Password={Password}";
    }
}

// 2. Create factory for migrations
public class ApplicationDbContextFactory
    : PostgreSqlDbContextFactoryBase<ApplicationDbContext, DatabaseOptions>
{
    protected override ApplicationDbContext CreateDbContext(
        DbContextOptions<ApplicationDbContext> options)
    {
        return new ApplicationDbContext(options);
    }
}

Service Registration

builder.Services.AddDbContext<ApplicationDbContext>((sp, options) =>
{
    var configuration = sp.GetRequiredService<IConfiguration>();
    var dbOptions = configuration.GetRequiredOptions<DatabaseOptions>();

    options.UseNpgsql(
        dbOptions.GetConnectionString(),
        npgsqlOptions =>
        {
            npgsqlOptions.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.FullName);
            npgsqlOptions.EnableRetryOnFailure(maxRetryCount: 3);
        });
});

PostgreSQL-Specific Features

public class ProductConfiguration : IEntityTypeConfiguration<Product>
{
    public void Configure(EntityTypeBuilder<Product> builder)
    {
        // PostgreSQL array types
        builder.Property(p => p.Tags)
            .HasColumnType("text[]");

        // JSONB
        builder.Property(p => p.Metadata)
            .HasColumnType("jsonb");

        // Full-text search index
        builder.HasIndex(p => p.Description)
            .HasMethod("GIN")
            .IsTsVectorExpressionIndex("english");
    }
}

Spatial Data (PostGIS)

public class Location : IEntity<LocationId>
{
    public LocationId Id { get; private set; }
    public Point Coordinates { get; set; } = null!;
}

// Configure DbContext
options.UseNpgsql(connectionString, x => x.UseNetTopologySuite());

// Spatial queries
var nearbyLocations = await _context.Locations
    .Where(l => l.Coordinates.Distance(point) <= radiusMeters)
    .ToListAsync();

Running Migrations

# Add migration
dotnet ef migrations add InitialCreate --project src/MyApp.Infrastructure

# Update database
dotnet ef database update --project src/MyApp.Infrastructure

# Generate SQL script
dotnet ef migrations script --output migration.sql

Configuration Example

{
  "Database": {
    "Host": "localhost",
    "Port": 5432,
    "Database": "myapp",
    "Username": "postgres",
    "Password": "secret",
    "MinPoolSize": 10,
    "MaxPoolSize": 100
  }
}

License

See LICENSE file in the repository root.

  • AuroraScienceHub.Framework.EntityFramework - Base EF Core functionality
  • AuroraScienceHub.Framework.Configuration - Configuration helpers
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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.0.7 299 11/20/2025
9.0.6 158 11/15/2025
9.0.5 114 11/8/2025
9.0.4 144 10/24/2025
9.0.3 181 10/15/2025
9.0.2 166 10/15/2025
9.0.1 173 10/14/2025
9.0.1-workflow-test-2.17 128 10/14/2025