title: Writing a Simple LINQ Query
body: <p>So I've been living in the dark ages of iterating through my data and finding what I'm interested the old fashioned way, but this project I thought I should make things more elegant and use LINQ where I know it can be used, but things aren't quite clicking.</p>
  
  <p>So I have two simple ObservableCollections and I want to pull all the data from one of them matching the current selected item of the other.  The objects are very simple...</p>
  
  <pre><code>public class foo
  {
      //....
      public string barID{ get; set; }
      //....
  }
  
  public class bar
  {
      public string ID { get; set; }
      //....
  }
  </code></pre>
  
  <p>So in my code I have the selected foo, and I want to create a collection of all bar's that have the matching barID...</p>
  
  <pre><code>ObservableCollection&lt;bar&gt; bars = 
      from data in fooCollection
      where data.barID == barCollection.SelectedItem.ID
      select data;
  </code></pre>
  
  <p>So I tried this based on the syntax for LINQ I was finding online, but this throws a compile error of unable to implicitly cast IEnumerable to ObservableCollection.  So I tried...</p>
  
  <pre><code>ObservableCollection&lt;bar&gt; bars = 
      (ObservableCollection&lt;bar&gt;)
      (from data in fooCollection
      where data.barID == barCollection.SelectedItem.ID
      select data);
  </code></pre>
  
  <p>Which compiles but throws a run-time error...</p>
  
  <pre><code>Unable to cast object of type 
  'WhereEnumerableIterator`1[TestProj.bar]' to type 
  'System.Collections.ObjectModel.ObservableCollection`1[TestProj.bar]'.
  </code></pre>
  
  <p>So I'm sure I could cast the object after the fact or do something else, but I was looking for as elegant a solution as possible, so a little help getting this simple LINQ statement together would be appreciated.  Also a simple explanation of what is happening behind the scenes would help immensely in helping me understand some of the LINQ basics.</p>