Entity Framework Code First Foreign Key adding Index as well

前端 未结 1 1245
旧时难觅i
旧时难觅i 2020-12-18 04:39

I have simple table definition in EF 6 code-first with simple foreign key.

public class Address
{
        /// 
        /// Gets or sets the id         


        
相关标签:
1条回答
  • 2020-12-18 05:10

    This is just a convention of Entity Framework. If you don't like it, then you can enable migrations on your project and change the migration to not include the foreign key. I disagree with your assertion that it is inefficient, though.

    To enable database migrations do the following:

    1. In the Package Manager console, type Enable-Migrations
    2. In the Package Manager console, type Add-Migration InitialMigration
    3. A new migration will be added to the Migrations folder, in it you will see an Up method with a few statements. Find the line that adds the foreign key and remove it.
    4. In the Package Manager console, type Update-Database to apply migrations.
    5. Repeat steps 2-4 for any new changes that come in.

    This is assuming you do not have a database yet and are starting from scratch.

    0 讨论(0)
提交回复
热议问题