none
How to prevent EF from creating an index on a foreign key RRS feed

Answers

  • Hello,

    Being confused why you want to remove the index, because it will be more effective for query with JOINS on a foreign key column which is an index.

    In program code, it is impossible since it is by designed. If you really do not want to create the index on the foreign key, you can use the migrations to create the database firstly. In the generated migration class file, find the line code for creating index and just remove it and use the update-database PCM to generate the database.

    For detail steps, you can follow this link:

    http://stackoverflow.com/questions/22225796/entity-framework-code-first-foreign-key-adding-index-as-well

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, March 13, 2014 9:50 AM
    Moderator

All replies

  • Hello,

    Being confused why you want to remove the index, because it will be more effective for query with JOINS on a foreign key column which is an index.

    In program code, it is impossible since it is by designed. If you really do not want to create the index on the foreign key, you can use the migrations to create the database firstly. In the generated migration class file, find the line code for creating index and just remove it and use the update-database PCM to generate the database.

    For detail steps, you can follow this link:

    http://stackoverflow.com/questions/22225796/entity-framework-code-first-foreign-key-adding-index-as-well

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, March 13, 2014 9:50 AM
    Moderator
  • Yes, normally the index is a good thing however this particular table needs a composite key because it is for a certain lookup only.

    Hope to see support for this in future releases as described here: https://entityframework.codeplex.com/workitem/1969

    Monday, March 17, 2014 2:20 PM