Skip to content

PgNameAttribute is ignored for enums in non-null SQL literal generation #684

Description

@JuanZamudioGBM

I'm using EF Core 2.1.2 and Npgsql.EntityFrameworkCore.PostgreSQL 2.1.1.1

The table is defined like this:

createtypeparty_country_typeas enum ('CITIZENSHIP', 'RESIDENCE', 'BIRTH');
createtableparty_country (
party_id uuid not null,
country_code char(3) null,
type party_country_type not null
);

I have an enum defined like this

publicenumCountryType{[PgName("CITIZENSHIP")]Citizenship=0,[PgName("RESIDENCE")]Residence=1,[PgName("BIRTH")]Birth=2,}

The context like this:

publicclassCrmContext:DbContext{staticCrmContext(){NpgsqlConnection.GlobalTypeMapper.MapEnum<CountryType>("party_country_type");}protectedoverridevoidOnModelCreating(ModelBuildermodelBuilder){modelBuilder.ForNpgsqlHasEnum("party_country_type",new[]{"CITIZENSHIP","RESIDENCE","BIRTH"});}}

And finally the class like this:

[Table("party_country")]publicclassPartyCountry:EntityBase{[Required][Column("party_id")]publicGuidPartyId{get;set;}[Required][StringLength(3)][MinLength(3)][Column("country_code")]publicstringCountryCode{get;set;}[Required][Column("type")]publicCountryTypeCountryType{get;set;}}

The above code works OK when inserting or updating, but when trying to search for an existing one it fails with the above message, for example the query in the code is

varparties=this.CrmContext.PartyCountry.Where(x =>x.CountryType==CountryType.Birth).FirstOrDefault();
Npgsql.PostgresException: '22P02: invalid input value for enum party_country_type: "birth"'

Its something wrong wit my code? Is there a workaround to run this? Or do i have to change my enums to lowercase?

Thanks

Activity

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions