none
Remove all Foreign key from an EDMX RRS feed

  • Question

  • Hello,

    I want to remove all the foreign keys from the EDMX.

    We have custom templates, which gives us POCO classes. We dont use entitySet or any entity tracking.

    We don't use navigation properites in our EDMX.Basically, the EDMX is currently being used to just add table/procedures and generate custom POCO classes based on entity and function imports.

    Can there be any problem if I remove all the foregin keys from the model ?

    Monday, November 18, 2013 11:31 AM

Answers

  • Hi Mukesh,

    >>If I dont have navigation properites, Do we need foreign key relationships to be maintained in the EDMX.

    Since you have the edmx file, you are using database first or model first. Whether there are navigation properties is decided by the foreign key relationship.

    If there are no foreign key relationships in the database, there are no navigaion properties in edmx.

    >>What if I remove all the foreign keys

    If we do this, then all navigation properties will go.

    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.

    • Marked as answer by Mukesh.Joshi Thursday, November 28, 2013 5:33 AM
    Tuesday, November 26, 2013 7:49 AM
    Moderator

All replies

  • If I understand, you have a database that has foreign keys, and you are considering removing the navigation properties from your model. (Whether a model has foreign key properties is a detail of how its navigation properties are handled).

    If you did that, you will be responsible for correctly setting the values of every foreign key column, and would have to specify any joins manually in LINQ.

    What do you hope to gain be doing this?

    David


    David http://blogs.msdn.com/b/dbrowne/

    Monday, November 18, 2013 5:12 PM
  • Thanks for your answer. My current EDMX is too large. It has 180 tables, and more then 1800 associations (Foreign key) in it.

    As I have already mentioned, the EDMX in our project is primarily used only for generating entities and procedures. To explain it more, in our T4 templates we have wrote class generators which just traverse through the EDMX and generates classes corresponding to the tables and procedures corresponding to the function imports. We don't use LINQ (we dont need it).

    I know the explanation seems to be very strange as usually LINQ/navigation properties are primarily used in the EDMX based projects.

    If I don't have any navigation properties in my EDMX, will it be useful to have foreign keys ?

    The issue I am facing is that I am not able to update EDMX any more as it has exceeded the limit of sql parameters (2100), i.e., when EDMX is updated it tries to validate schema via calling a select query on the Database Schema to validate everything which is there in EDMX. If EDMX has more then 2100 informations (entity/association) it will crash and designer will not update the EDMX.

    So I was thinking if the associations is not useful (withing navigation property), I can remove those.

    I just wish to know what are the areas which can be impacted with such change ?

    Tuesday, November 19, 2013 5:16 AM
  • >If I don't have any navigation properties in my EDMX, will it be useful to have foreign keys ?

    So what are you proposing to do?  Foreign Keys exist in the database, not the EDMX. 

    David


    David http://blogs.msdn.com/b/dbrowne/

    Tuesday, November 19, 2013 1:36 PM
  • Hello Mukesh,

    The navigation properties is based on the foreign Keys. If you delete these associations, the mapping will fail.

    >>The issue I am facing is that I am not able to update EDMX any more as it has exceeded the limit of sql parameters (2100)

    For this, I recommend to split tables that has associations with ecah other to multiple edmx models.


    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.

    Wednesday, November 20, 2013 6:10 AM
    Moderator
  • Hello David,

    If I dont have navigation properites, Do we need foreign key relationships to be maintained in the EDMX. What if I remove all the foreign keys ?

    Monday, November 25, 2013 5:09 AM
  • Hi Mukesh,

    >>If I dont have navigation properites, Do we need foreign key relationships to be maintained in the EDMX.

    Since you have the edmx file, you are using database first or model first. Whether there are navigation properties is decided by the foreign key relationship.

    If there are no foreign key relationships in the database, there are no navigaion properties in edmx.

    >>What if I remove all the foreign keys

    If we do this, then all navigation properties will go.

    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.

    • Marked as answer by Mukesh.Joshi Thursday, November 28, 2013 5:33 AM
    Tuesday, November 26, 2013 7:49 AM
    Moderator