efcore.pg icon indicating copy to clipboard operation
efcore.pg copied to clipboard

Type for Arrays of Enums not set during migration

Open jnb-source opened this issue 8 years ago • 5 comments

With an enum type mapped like so: protected override void OnModelCreating(ModelBuilder builder) { builder.ForNpgsqlHasEnum("Mood", new[] { "happy", "sad" }); }

static MyDbContext() { NpgsqlConnection.GlobalTypeMapper.MapEnum<Mood>("Mood"); }

And an array defined like so:

public List<Mood> Moods{ get; set; }

Throws : 42704: type "Mood[]" does not exist

I think the issue is the generated SQL does not type the array specifically, like so:

ARRAY['happy','sad']::Mood[]

jnb-source avatar Jun 26 '18 14:06 jnb-source

Issue was caused by the casing of the enum.

When mapping used mood instead of Mood the migration went smoothly.

I'll update the docs to point out this caveat.

jnb-source avatar Jun 26 '18 15:06 jnb-source

This looks like a duplicate of #440.

Can you post some version information?

austindrenski avatar Jun 26 '18 16:06 austindrenski

With an enum type mapped like so:

protected override void OnModelCreating(ModelBuilder builder) 
{ 
    builder.ForNpgsqlHasEnum("Mood", new[] { "happy", "sad" }); 
}

Throws :

42704: type "Mood[]" does not exist

That configuration is correct for the quoted PostgreSQL identifier:

CREATE TYPE "Mood" AS ENUM ('sad', 'ok', 'happy');

austindrenski avatar Jun 26 '18 16:06 austindrenski

Yep, agree with @austindrenski that this is a dup of #440 - I intend to release 2.1.1 this weekend so this should be gone. @JNBarnes can you please test the latest nupkg from the stable feed and report if it resolves the issue for you?

roji avatar Jun 26 '18 22:06 roji

Closing as no additional info was provided within 7 days. But please feel free to post back here with the relevant information and I'll reopen if necessary.

roji avatar Jul 14 '18 11:07 roji