Model-First - Many-to-many relationships w/ additional fields

4 posts, 1 answers
  1. Hunter
    Hunter avatar
    11 posts
    Member since:
    Apr 2013

    Posted 31 Jul 2013 Link to this post

    Could someone please tell me the difference between the following two documents:
    Using Custom Join Table
    Without a Join Table

    Almost all of my join tables will have additional properties. I am assuming I will not be using this method much: Using Default Join Table
    I just want to make sure I am on the right track by creating my own join tables using the above 2 methods. I just don't know the difference between them. They seem the same to me.
  2. Answer
    Kristian Nikolov
    Admin
    Kristian Nikolov avatar
    206 posts

    Posted 01 Aug 2013 Link to this post

    Hi Hunter,

    While both approaches result in a many to many association, there is a very important difference between them and depending on your scenario, you may prefer one over the other.

    In the Custom Join Table approach you create the join table using the Table Editor. Although you can customize the join table by adding additional columns, you will not be able to execute queries against it in your project because there is no entity mapped to it.

    The Without a Join Table article has a bit misleading name, because in the end you still get a join table. With this approach however, your join table is mapped to an entity (CustomerOrder) and that means you can query it from your OpenAccess context.

    I hope this information was helpful to you. In case you have additional questions, do not hesitate to get back to us.

    Regards,
    Kristian Nikolov
    Telerik
    OpenAccess ORM Q2 2013 brings you a more powerful code generation and a unique Bulk Operations support with LINQ syntax. Check out the list of new functionality and improvements shipped with this release.
  3. DevCraft banner
  4. Hunter
    Hunter avatar
    11 posts
    Member since:
    Apr 2013

    Posted 01 Aug 2013 Link to this post

    Very good response. Now I understand. When would be a good time to use the automated default join approach?
  5. Kristian Nikolov
    Admin
    Kristian Nikolov avatar
    206 posts

    Posted 02 Aug 2013 Link to this post

    Hi Hunter,

    The Default Join Table approach is useful when you need to quickly create many to many association between entities and no customization is needed. This method is easy, but does not offer much control and thus is preferred in simple scenarios.

    As you have already noticed, m:n association based on a default join table is not registered as a schema change when migrating your database. This behavior is expected and the reason for it is that when creating the association, the default join table is not added to the model metadata - no additional table can be seen in the Model Schema Explorer. Thus when migrating, there are no differences between the model and database schemata.
    If you have a scenario where you need to update your database with m:n association from your Domain Model (in a Model First approach), you will need to use either Custom Join Table or the so called Without a Join Table approach.

    If you have further inquiries do not hesitate to contact us again.

    Regards,
    Kristian Nikolov
    Telerik
    OpenAccess ORM Q2 2013 brings you a more powerful code generation and a unique Bulk Operations support with LINQ syntax. Check out the list of new functionality and improvements shipped with this release.
Back to Top