locked
Foreign Key Relationship ignored - Why? RRS feed

  • Question

  • Hello there,

    I am using SQL Server 2008 and the .NET 4 Entity Framework Release. When generating an Entity Data Model from my existing database, one certain relationship is ignored and not imported into the model. The expected navigation property which I expect to be generated, is missing. It is a regular one to many relationship between two tables. There are two other relationships on the same table which are generated properly.

    When generating the database diagram inside SQL Server Management Studio, the relationship is correctly displayed/generated, which means that the relation itself seems to be correct.

    Does anyone have a clue what could be wrong here? I am really in the dark....

     

    Thank you very much for a hint.

     

    Best regards,

    André Gasser

    Saturday, December 18, 2010 1:06 AM

Answers

  • Hello André,

     

    Welcome to MSDN forum,  and thank you for posting in MSDN Forum.  I am Jackie Sun.

     

    Based on your issue,  in my opinion,  if you can’t find the reason about this, you could add the one to many relationship between two tables manually to make sure all the code is correct.  Then if you have any time,  you can look for the reason.

    The method to add the relationship is as the following:

    1.       Right click the table you want to add the relationship and select “Add”.

    2.       Then select “Association…”.

    The next you do is select the other table and choose the relationship as one to many.

     I hope this will help resolve your problem. If anything is unclear, please free feel to let us know.

     

    Thank you for your understanding and support.

    I look forward to hearing from you.

     

    Best Regards,


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Jackie-Sun Monday, December 27, 2010 9:35 AM
    Tuesday, December 21, 2010 5:46 AM
  • Hi Jakie-Sun!

    I am facing the same problem. But I can't just add relationship manually because I have 25 tables to link... I don't want to do this every time I regenerate the model...

    Is there a solution that I can apply on my situation?

    Thanks a lot for your response.

    (sorry for my poor english)

    Emmanuelle

    EDIT:

    Ok I found the solution!! :o)

    http://blog.degree.no/2012/09/missing-relations-in-entityframework-model-when-generating-from-database/

    Maybe this will help others! :o)

    • Edited by Kitiara79 Tuesday, April 16, 2013 2:15 PM SolutionFound
    • Proposed as answer by Kitiara79 Tuesday, April 16, 2013 2:15 PM
    • Marked as answer by Jackie-Sun Tuesday, June 18, 2013 1:58 AM
    Tuesday, April 16, 2013 12:57 PM

All replies

  • Hello André,

     

    Welcome to MSDN forum,  and thank you for posting in MSDN Forum.  I am Jackie Sun.

     

    Based on your issue,  in my opinion,  if you can’t find the reason about this, you could add the one to many relationship between two tables manually to make sure all the code is correct.  Then if you have any time,  you can look for the reason.

    The method to add the relationship is as the following:

    1.       Right click the table you want to add the relationship and select “Add”.

    2.       Then select “Association…”.

    The next you do is select the other table and choose the relationship as one to many.

     I hope this will help resolve your problem. If anything is unclear, please free feel to let us know.

     

    Thank you for your understanding and support.

    I look forward to hearing from you.

     

    Best Regards,


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Jackie-Sun Monday, December 27, 2010 9:35 AM
    Tuesday, December 21, 2010 5:46 AM
  • Does the foreign key constraint refer to the primary key of the referenced table?   Entity Framework doesn't currently support relationships that correspond to foreign key constraints that reference non-primary candidate keys.

    --- Will.

    Tuesday, December 21, 2010 9:00 PM
  • Hi Jakie-Sun!

    I am facing the same problem. But I can't just add relationship manually because I have 25 tables to link... I don't want to do this every time I regenerate the model...

    Is there a solution that I can apply on my situation?

    Thanks a lot for your response.

    (sorry for my poor english)

    Emmanuelle

    EDIT:

    Ok I found the solution!! :o)

    http://blog.degree.no/2012/09/missing-relations-in-entityframework-model-when-generating-from-database/

    Maybe this will help others! :o)

    • Edited by Kitiara79 Tuesday, April 16, 2013 2:15 PM SolutionFound
    • Proposed as answer by Kitiara79 Tuesday, April 16, 2013 2:15 PM
    • Marked as answer by Jackie-Sun Tuesday, June 18, 2013 1:58 AM
    Tuesday, April 16, 2013 12:57 PM
  • Cool~ That's great!

    Jackie Sun

    Tuesday, June 18, 2013 1:58 AM