Hobbiton.PostgresEnumExtension 0.0.1

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

Hobbiton.PostgresEnumExtension

A lightweight library that automatically discovers and maps all your C# enums to PostgreSQL enum types using a simple attribute. No more manual MapEnum calls for every enum — just decorate and go.

Installation

dotnet add package Hobbiton.PostgresEnumExtension

Usage

1. Decorate your enums with [PostgresEnum]

using PostgresEnumExtension;

[PostgresEnum]
public enum OrderStatus
{
    Pending,
    Processing,
    Shipped,
    Delivered,
    Cancelled
}

[PostgresEnum]
public enum UserRole
{
    Admin,
    Moderator,
    Member,
    Guest
}

2. Register enums on the NpgsqlDataSourceBuilder

var dataSourceBuilder = new NpgsqlDataSourceBuilder(connectionString);
dataSourceBuilder.MapAllEnums(); // discovers and maps all [PostgresEnum] types
var dataSource = dataSourceBuilder.Build();

3. Register enums in your DbContext configuration

services.AddDbContext<AppDbContext>(options =>
    options.UseNpgsql(dataSource, npgsql =>
    {
        npgsql.MapAllEnums(); // maps enums for EF Core with snake_case type names
    })
);

4. Use the enums in your entities as usual

public class Order
{
    public int Id { get; set; }
    public OrderStatus Status { get; set; }
}

How It Works

  • [PostgresEnum] — An attribute you place on any enum that should be mapped to a PostgreSQL enum type.
  • MapAllEnums() (NpgsqlDbContextOptionsBuilder) — Scans all loaded assemblies for enums decorated with [PostgresEnum] and calls MapEnum for each one, using a snake_case version of the enum name as the PostgreSQL type name (e.g., OrderStatusorder_status).
  • MapAllEnums() (NpgsqlDataSourceBuilder) — Does the same assembly scan and registers the enums on the data source builder so Npgsql knows how to read and write them.

Requirements

License

See the LICENSE file for details.

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.

Version Downloads Last Updated
0.0.1 87 5/13/2026