I have Table1 and Table2.
Table1 has a foreignKey pointing to Table2 primary Key. It could be a bad design, but I cannot change it as it is old.
Now I want to use EF with code first and tried to generate a model and DbContext classes for it through the following command:
dotnet ef dbcontext scaffold "Server=Server1;Database=DBName;Integrated Security=True;MultiSubnetFailover=True;" Microsoft.EntityFrameworkCore.SqlServer -o Models
And getting the following error:
The foreign key {'ForeignKeyId'} cannot be added to the entity type 'TABLENAME' because a foreign key on the same properties already exists on entity type 'TABLENAME' and also targets the key {'FOREIGNKEY'} on 'FOREIGNKEY_PrimaryTable'.
Is there a way I can overcome this error?