Joins using collections

2 posts, 0 answers
  1. Craig
    Craig avatar
    3 posts
    Member since:
    Jun 2009

    Posted 01 Jul 2009 Link to this post

    How do we join one object on a collection of objects that are stored in another object (using Linq).

    e.g.

    users object

    roles object

    roles object has a collection of user objects.

    we want to get a list of users that are mapped to a single role.

    as standard sql it would be

    select users.* from users
        inner join users_in_roles on users_in_roles.user_id=users.id
        inner join roles on users_in_roles on user_in_roles.roles_id=roles.id
       where roles.id=76


  2. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 02 Jul 2009 Link to this post

    Hello Craig,

    I guess you are using the Reverse mapping approach. Please, take a look at this knowledge base article to get familiar with the process. Note the last step described - you have to enable the inverse collection option in order to get a list of Users in the Role class. After doing this, you will not even have to execute a query at all - each Role will have the collection with the related Users and you can reach it by using the Role.Users property.

    Greetings,
    Alexander
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
Back to Top