Question: I'm using a self tracking entity model. `ProductInstallation` is a DTO which contains all the details about the product installation for a company. 

The `UserRoles` entity holds the relationship in-between the Product-System Role-UserID.

As an example:

> 
> Product: Inventory
> 
> 
> System Role : PurchasingUser
> 
> 
> User ID : hasithaH <- (Suppose me)
> 
> 
> 

using the below LINQ query, I can get the distinct UserIDs.

```
string[] userIDs = productInstallation.UserRoles
                  .Select(u=>u.UserID).Distinct().ToArray();

```

now I need to get all the User Profiles for the UserIDs I queried in above steps.

```
productInstallation.SystemUsers = context.SystemUsers.Select(u=> u.UserID ..??? 

```

In SQL point of view, this is the query I want:

```
Select * from SystemUsers where UserID in ('UserA','UserB','UserC')

```

How should I write a LINQ query to get this done?

Answer: 
You write it as follows: 

```
var result = context.SystemUsers.Where(su => 
               productInstallation.UserRoles.Any(ur => su.UserID == ur.UserId));

```

Or if both sources are not `IQuerable` from the same db:

```
string[] userIDs = productInstallation.UserRoles
                  .Select(u=>u.UserID).Distinct().ToArray();

var result = context.SystemUsers.Where(su => 
                   userIDs.Contains(su.UserID));

```
You can try this:

```
productInstallation.SystemUsers = 
context.SystemUsers.FindAll(u=> userIDs.Contains(u.UserID))

```