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
I'm using EF Core 2.1.2 and Npgsql.EntityFrameworkCore.PostgreSQL 2.1.1.1
The table is defined like this:
I have an enum defined like this
The context like this:
And finally the class like this:
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
Its something wrong wit my code? Is there a workaround to run this? Or do i have to change my enums to lowercase?
Thanks