5

Given the following Structure

public class WorkOrderItem 
{
    [Key] 
    public long WorkOrderItemId { get; set; }
    public virtual ICollection<Job> Jobs { get; set; }      
}

public class Job 
{
    [Key]
    public long JobId { get; set; }
    public long? WorkOrderItemId { get; set; }
    public virtual Item Item { get; set; }
    public virtual Element ResultElement { get; set; }
}

How would i get a list of Items where the item had a job that the ResultElementid was in a List<long>()?

2

1 Answer 1

11

You can use Any + Contains:

var query = workOrderItems
    .Where(item => item.Jobs.Any(j => longList.Contains(j.ResultElement.Id)));

( presuming that the class Element has an Id property since you've stated ResultElementid )

Sign up to request clarification or add additional context in comments.

1 Comment

I always forget some vital Linq method, in this case it was ANy(). Cheers.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.