title: Using Linq to objects to get to an object deep in the hierarchy
body: <p>Quite new to Linq, and I'm struggling with this one. Basically I have a collection of "Workers", which each object itself contains a collection of "WorkerOperatorAssignments", which each object contains an "Operator" object.</p>
  
  <blockquote>
    <p>Workers (collection) -> WorkerOperatorAssignments (collection) ->
    Operator (object)</p>
  </blockquote>
  
  <p>I wish to return the Operator record in certain circumstances using Linq. I have the following so far:</p>
  
  <pre><code>Operator TillLogin = WorkersCollection.Where(w =&gt; 
      w.WorkerOperatorAssignments.Any(a =&gt; 
          a.Operator.TypeCode == OperatorTypeCode.TillOperator)
  );
  </code></pre>
  
  <p>But this obviously returns a collection of workers which contain an Operator record as per the where clause. How do I return just that actual Operator record in this condition?</p>
  
  <p>UPDATE:</p>
  
  <p>Thank you all for the answers, helped me a bunch. I have amended my full query to:</p>
  
  <pre><code>Operator TillLogin = Response.Payload.Party.Workers
        .SelectMany(w =&gt; w.WorkerOperatorAssignments)
        .Select(a =&gt; a.Operator)
        .Where(o =&gt; o.TypeCode.Trim() == OperatorTypeCode.TillOperator)
        .SingleOrDefault();
  </code></pre>