title: Multiple Order By with LINQ
body: <p>I start with a basic class that I want to manipulate in a List using LINQ, something like the following:</p>
  
  <pre><code>public class FooBar   
  {  
      public virtual int Id { get; set; }  
      public virtual string Foo { get; set; }  
      public virtual string Bar { get; set; }
  }
  </code></pre>
  
  <p>This is what I ultimately found out to solve my problem using the non lambda LINQ stuff.</p>
  
  <pre><code>// code somewhere else that works and gets the desired results  
  var foobarList = GetFooBarList();  // Abstracted out - returns List&lt;Foobar&gt;  
  
  // Interesting piece of code that I want to examine
  var resultSet = from foobars in foobarList  
                  orderby foobars.Foo, foobars.Bar  
                  select foobars;
  
  // Iterate and do something interesting  
  foreach (var foobar in resultSet)  
  {  
      // Do some code  
  }
  </code></pre>
  
  <p>What I'm really curious about is if the same can be accomplished using the Lambda based extension methods off of generic <code>IEnumerable</code> to accomplish the same thing.  Google tells me I can do something like the following to accomplish it:</p>
  
  <pre><code>var resultSet = foobarList.OrderBy(x =&gt; new {x.Foo, x.Bar})  
                            .Select(x=&gt;x);
  </code></pre>
  
  <p>However if I do that I get a runtime error when I hit the <code>foreach</code> statement.  The error tells me that at least one object has to implement <code>IComparible</code>, which I can see that since I'm using an anonymous type for the <code>.OrderBy()</code> method.</p>
  
  <p>So is there a way to accomplish what I want using the Lambda way?</p>