This is a migrated thread and some comments may be shown as answers.

Navigation Properties for Many to Many relationship

1 Answer 37 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Gary
Top achievements
Rank 1
Gary asked on 10 Aug 2015, 05:47 PM

I am working with an existing database which I was able to import into a Domain Model (rling) file. As this is new, greenfield development I am continually adding and revising the tables and their relationships (which by the way, has been made very easy with this ORM!) and am frequently updating the model from the database ... anyway ... I have a situation where I have created a many to many relationship in the database. It involves a PRODUCTS table, a PACKAGES table, and a join table which allows me to define multiple products in a single package and a product in multiple packages. I was expecting to see a navigation property, in the domain model, on the PRODUCT model, which would allow me to list the packages that the product was participating in ... PRODUCT.PACKAGES, and vice versa ... PACKAGE.PRODUCTS. Instead each model has a ​navigation property ​which references the ​join table instead. PRODUCT.PRODUCT_PACKAGES_JOIN and PACKAGE.PRODUCT_PACKAGES_JOIN (pseudo-code). Is there a way to add navigational properties to each end of the relationship so I do not have to go through the join table?

 

I found this article ... How to: Manage Many-to-Many Associations... but the example it gave appeared to be some configuration code, which I have not yet had to involve myself with, so I do not know where or how that would work into the project.

 

Any help would be greatly appreciated! Thanks!

1 Answer, 1 is accepted

Sort by
0
Boris Georgiev
Telerik team
answered on 13 Aug 2015, 02:46 PM
Hello Gary,

When you add a new join table in the database, the table could be recognized as a basic table instead of join table and because of that in the model it will occur as a class with two associations. In this case, you should manually create the Many-to-Many association in the Domain Model.

To do that, you could follow these steps:
1) Delete the Domain Class associated with the Join table from the Domain Model.
2) Open Model Schema Explorer and find the Join table.
3) From the Properties window change IsJoinTable property to True.
4) Create an association between the two classes and open the association for edit with the Association Editor.
5) In RelationalView check Use Join Table check-box and select the Join Table from the drop down.
6) Manually Map the Ids from the tables to the Join table.

Then you will have Many-to-Many association between the two classes.

I hope that helps.

Regards,
Boris Georgiev
Telerik
 
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
Tags
Data Access Free Edition
Asked by
Gary
Top achievements
Rank 1
Answers by
Boris Georgiev
Telerik team
Share this question
or