Skip to content

Mapping issues with schema-scoped enums #554

Description

@austindrenski

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");}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions