❔ Entity Framework 7 model property as enum is giving conflicts when running migration
I'm trying to create a many to many "pivot" model where it haves 2 fields "GroupId" and "SubscriptionId"
I have a SubscriptionType enum:
When i run the migration it gives me this warnings:
"The foreign key property 'GroupSubscription.SubscriptionId1' was created in shadow state because a conflicting property with the simple name 'SubscriptionId' exists in the entity type, but is either not mapped, is already used for another relationship, or is incompatible with the associated primary key type. See https://aka.ms/efcore-relationships for information on mapping relationships in EF Core."
Introduction to relationships - EF Core
How to configure relationships between entity types when using Entity Framework Core
12 Replies
FooId
is automatically treated as the foreign key to Foo
. I'm not sure if enums can be used as keysmaybe if you have an explicit conversion defined
Yeah it seems that EF doesn't have compatibility with enums
Because when migration created the foreign key FooId was duplicated
Well... enums are enums
If your database had support for enums and it was set up, they would be... enums in the database
I wouldn't be satisfied with leaving it to EF, anyway
you can configure EF to handle your enums explicitly, without much trouble
store 'em as ints, strings, or define a static data table
NpgSQL handles enums really well, after you set it up
Since Postgres supports enums as enums, without converting them to
VARCHAR
s or INT
syup
not sure if that's been translated into EF
Well, NpgSQL does translate it, and I can use enums as enums without having to do any weird stuff
the EF driver for NpgSQL, you mean?
ye
cool
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.