Skip to content
This repository has been archived by the owner on Sep 22, 2024. It is now read-only.

Genfic/Npgsql-Enum-Helpers

Repository files navigation

Npgsql Enum Helpers

Source generator that generates code used to register and map enums to NpgSQL

Usage

  1. Add the [NpgsqlEnum] attribute to selected enums
[NpgsqlEnum]
enum Animals
{
    Cat,
    Dog,
    Parrot,
    Tardigrade
}
  1. Call MapPostgresEnums() on NpgsqlConnection.GlobalTypeMapper
public MyDbContext(DbContextOptions options) : base(options)
{
    NpgsqlConnection.GlobalTypeMapper.MapPostgresEnums(); 👈
}
  1. Call RegisterPostgresEnums() on your ModelBuilder
protected override void OnModelCreating(ModelBuilder builder)
{
    base.OnModelCreating(builder);

    builder.RegisterPostgresEnums(); 👈
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages