Enum mapping works as advertised given a CLR enum (SomeEnum) and an equivalent PostgreSQL enum (some_enum):
staticSomeDbContext(){// works as advertised for public.some_enumNpgsqlConnection.GlobalTypeMapper.MapEnum<SomeEnum>();}However, if some_enum is created in some_schema rather than the public schema, the normal mapping behavior does not work:
staticSomeDbContext(){// does *not* work for some_schema.some_enumNpgsqlConnection.GlobalTypeMapper.MapEnum<SomeEnum>();}Instead, an explicit schema-qualified name needs to be provided:
staticSomeDbContext(){// does work for some_schema.some_enumNpgsqlConnection.GlobalTypeMapper.MapEnum<SomeEnum>("some_schema.some_enum");}This behavior makes sense to a certain extent, but it would be nice if the default schema confgured for the DbContext could be detected and used for enum mapping:
protectedoverridevoidOnModelCreating(ModelBuilderbuilder)=>builder.HasDefaultSchema("some_schema");
CREATESCHEMAtest;
CREATETYPEmapped_enumAS ENUM ('happy', 'sad');
CREATETYPEtest.manual_enum AS ENUM ('happy', 'sad');
CREATETABLEsome_table (
id int,
mapped_enum mapped_enum,
manual_enum test.manual_enum
);publicclassSomeTable{publicintId{get;set;}publicMappedEnumMappedEnum{get;set;}publicManualEnumManualEnum{get;set;}}publicclassEnumContext:DbContext{publicDbSet<SomeTable>SomeTable{get;set;}staticEnumContext(){NpgsqlConnection.GlobalTypeMapper.MapEnum<MappedEnum>();NpgsqlConnection.GlobalTypeMapper.MapEnum<ManualEnum>();}publicEnumContext(DbContextOptionsoptions):base(options){}protectedoverridevoidOnModelCreating(ModelBuilderbuilder)=>builder.ForNpgsqlHasEnum("mapped_enum",new[]{"happy","sad"}).HasDefaultSchema("test");}
Enum mapping works as advertised given a CLR enum (
SomeEnum) and an equivalent PostgreSQL enum (some_enum):However, if
some_enumis created insome_schemarather than thepublicschema, the normal mapping behavior does not work:Instead, an explicit schema-qualified name needs to be provided:
This behavior makes sense to a certain extent, but it would be nice if the default schema confgured for the
DbContextcould be detected and used for enum mapping: