Query many-to-many tables

Thread is closed for posting
2 posts, 1 answers
  1. Marcel
    Marcel avatar
    42 posts
    Member since:
    Jan 2014

    Posted 30 Jul 2015 Link to this post


     I just strated out with the OpenAccess framework and modeled, the following data structure:

    User <--> UserRole <--> Module

    So a many to many relation exists between User and UserRole and a many to many relation exist between UserRole and Module.

    The OpenAcess framework has hidden the two many-to-many junction tables.


    I now want to run a query which gives me all Modules for a given user.

    When I execute the following query I get the runtime exception "Join left side undefined".


    List<Module> modules = (from geb in Context.Gebruikers
                            from gr in Context.GebruikerRoles
                            from mod in Context.Modules
                            where geb.GebruikerID == gebruikerId
                            select mod).ToList();


    What am I missing here?



  2. Answer
    Viktor Zhivkov
    Viktor Zhivkov avatar
    324 posts

    Posted 04 Aug 2015 Link to this post

    Hi Marcel,

    I am afraid that the best way to express a query spanning two many-to-many relationship is to hand craft a stored procedure. LINQ is not particularly suited for such scenario and you may have to split the query into several pieces, execute them one by one and merge the results in-memory which in most cases is a lot slower and inefficient.
    Here is a link to our online documentation that can guide you how to execute a stored procedure.

    If you need any further assistance do not hesitate to contact us again.

    Viktor Zhivkov
    Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
Back to Top