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

Joins using collections

1 Answer 66 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Craig
Top achievements
Rank 1
Craig asked on 01 Jul 2009, 10:40 PM
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


1 Answer, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 02 Jul 2009, 02:59 PM
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.
Tags
LINQ (LINQ specific questions)
Asked by
Craig
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or