This is just an agreement with the Entity Framework. If you do not like this, you can enable migration in your project and change the migration to not include a foreign key. I do not agree with your statement that it is ineffective.
To enable database migration, follow these steps:
- In the Package Manager console, enter
Enable-Migrations - In the package manager console, enter
Add-Migration InitialMigration - A new migration will be added to the Migrations folder, in which you will see the
Up method with several statements. Find the line that adds the foreign key and deletes it. - In the Package Manager console, enter
Update-Database to apply the migration. - Repeat steps 2-4 for any new changes that come in.
It is assumed that you do not yet have a database and start from scratch.
source share