none
Entity not appearing in Model Diagram RRS feed

  • Question

  • Hi.

    I have a table (tblOther) whose Primary Key consists of the Primary Keys of two other tables (tblThis, tblThat):

    tblThis tblThat tblOther

    ThisId(PK) ThatId(PK) ThisId(PK)

    ThatId(PK)

     

    I use tblOther to relate the data in tblThis to tblThat.

    When I add tblOther to my EF model it does not appear in the diagram and I can't reference it through code.  However, if I add an Identity field to tblOther and add it to the Model it does appear and I can then use it.

    Why is this?

     

    Kind regards,

    Ben

    Sunday, November 20, 2011 2:49 PM

Answers

  • Hi Ben;

    When you have a table in your database that only has the primary keys of the two other tables it is called a Junction table or also goes by the name Bridge table. This setup is a Many to Many relationship between the two other tables. When you add these three tables into your model you will only see the two tables that have the Many to Many relationships and NOT the Junction table. When you look at the tables that it does display you will note that the navigation properties will point to the other end of the Many to Many relationship, internally it uses the Junction table to get the related tables. When you add an extra property to the Junction table it no longer acts as a Junction table and so it will be displayed in the model. This is by design,

    See this post.
    Entity Framework: Queries involving many to many relationship tables

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Sunday, November 20, 2011 3:30 PM

All replies

  • Hi Ben;

    When you have a table in your database that only has the primary keys of the two other tables it is called a Junction table or also goes by the name Bridge table. This setup is a Many to Many relationship between the two other tables. When you add these three tables into your model you will only see the two tables that have the Many to Many relationships and NOT the Junction table. When you look at the tables that it does display you will note that the navigation properties will point to the other end of the Many to Many relationship, internally it uses the Junction table to get the related tables. When you add an extra property to the Junction table it no longer acts as a Junction table and so it will be displayed in the model. This is by design,

    See this post.
    Entity Framework: Queries involving many to many relationship tables

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Sunday, November 20, 2011 3:30 PM
  • Hi Fernando.

    Thanks for the prompt reply and explanation.  I'll remove the idenity column on my Bridge table and look at using the Navigation properties instead.

    Also, apologies - my table "diagram" seemed to lose it's formatting in my original post... but you seemed to understand what I meant anyway :)

    Cheers,

    Ben

    Sunday, November 20, 2011 5:41 PM
  •  

    Not a problem Ben, always glad to help.

     


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Sunday, November 20, 2011 5:53 PM