m:n prefetch path

Posts   
 
    
ITFromBit
User
Posts: 8
Joined: 19-Feb-2021
# Posted on: 13-Jan-2022 13:45:40   

The documentation says:

"Prefetch Paths can also be used to fetch m:n related entities, they work the same as other related entities. There is one caveat: the intermediate entities are not fetched with an m:n relation Prefetch Path."

But there is no example on how to do this. Example: category - category2source - source

I can only add the prefetchpath on category to categorysource and but not from category to source directly. All I want is a list of categories with their sources, without the intermediate m:n table. How can this be done?

Best M

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 13-Jan-2022 18:19:10   

M:n relation are not added by default, you either need to define them in the Designer, or if you are on database first development, then you can set the "Auto add many to many relationships" setting in the Designer to true. This can be found under: Settings/Conventions/Entity Model/Database First Development/ Reverse Engineering

Then you should end up with a a navigator for the end of the relation (e.g. Product.OrderCollectionViaOrderDetails) which you can fetch via prefetchPath as well. You will find the corresponding "prefetchPath-via" generated, for you to use.