❔ 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"
public class GroupSubscription
{
public int Id { get; set; }
public int GroupId { get; set; }
public SubscriptionType SubscriptionId { get; set; }
public Group Group { get; set; } = null!;
public Subscription Subscription { get; set; } = null!;

}
public class GroupSubscription
{
public int Id { get; set; }
public int GroupId { get; set; }
public SubscriptionType SubscriptionId { get; set; }
public Group Group { get; set; } = null!;
public Subscription Subscription { get; set; } = null!;

}
I have a SubscriptionType enum:
public enum SubscriptionType
{
Basic = 1,
}
public enum SubscriptionType
{
Basic = 1,
}
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
Angius
Angius11mo ago
FooId is automatically treated as the foreign key to Foo. I'm not sure if enums can be used as keys
JakenVeina
JakenVeina11mo ago
maybe if you have an explicit conversion defined
mauriziopatino
mauriziopatino11mo ago
Yeah it seems that EF doesn't have compatibility with enums Because when migration created the foreign key FooId was duplicated
Angius
Angius11mo ago
Well... enums are enums If your database had support for enums and it was set up, they would be... enums in the database
JakenVeina
JakenVeina11mo ago
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
Angius
Angius11mo ago
NpgSQL handles enums really well, after you set it up Since Postgres supports enums as enums, without converting them to VARCHARs or INTs
JakenVeina
JakenVeina11mo ago
yup not sure if that's been translated into EF
Angius
Angius11mo ago
Well, NpgSQL does translate it, and I can use enums as enums without having to do any weird stuff
JakenVeina
JakenVeina11mo ago
the EF driver for NpgSQL, you mean?
Angius
Angius11mo ago
ye
JakenVeina
JakenVeina11mo ago
cool
Accord
Accord11mo ago
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.