title: Using Lambda / Linq Filter Parent Collection based on Child Items
body: <p>I have the following two classes;</p>
  
  <pre><code>public class Order
  {
      public int Id {get;set;}
      public List&lt;Item&gt; Items {get;set;}
      public DateTime CreatedOn {get;set;}
  }
  
  public class Item
  {
      public int Code {get;set;}
      public int SupplierId {get;set;}
      public string Name {get;set;}
      public decimal Price {get;set;}
  }
  </code></pre>
  
  <p>I have a List of Orders, and each order contains a number of different items.    I am wanting to filter the Order List, so that I can achieve the following;</p>
  
  <ul>
  <li>Return all orders where at least 1 item in the Item List has SupplierId = 1</li>
  <li>Don't return any orders if no items match SupplierId = 1</li>
  </ul>
  
  <p><strong>UPDATE</strong></p>
  
  <p>How can I expand the results as well so that I only return orders and Items that have SupplierId = 1</p>
  
  <p>This is what I tried so far which now works.  But how can I compact it further;</p>
  
  <pre><code> List&lt;Order&gt; OrderList = new List&lt;Order&gt;();
  
   foreach(Order order in Order.Get(1))
   {
       Order tmpOrder = order;
       tmpOrder.Items = order.Items.Where(x =&gt; x.SupplierId == 1).ToList();
  
       if (tmpOrder.Items.Count &gt; 0)
           OrderList.Add(tmpOrder );
    }
  </code></pre>