title: C# LINQ compound ordering on 3 columns
body: <p>I have an object with many fields, but I want to order on 3 columns (boolean [IsValid], int [Count], and date [CreateDate]), conditionally dependent on the boolean.</p>
  
  <p>Data:</p>
  
  <pre><code>|| ID || IsValid || Count || CreateDate  ||
  ==========================================
  || 1  ||  True   || 3     || 2016-05-01 ||
  || 2  ||  True   || 2     || 2016-07-12 ||
  || 3  ||  False  || NULL  || 2015-06-16 ||
  || 4  ||  False  || 1     || 2015-01-01 ||
  </code></pre>
  
  <p>The order I want is:
  1) Valid items first
  2) If valid, order by Count, else by CreateDate (essentially <code>(o.IsValid) ? o.Count : o.CreateDate</code>, but that didn't work), so that the order would be</p>
  
  <pre><code>|| ID || IsValid || Count || CreateDate  ||
  ==========================================
  || 2  ||  True   || 2     || 2016-07-12 ||
  || 1  ||  True   || 3     || 2016-05-01 ||
  || 4  ||  False  || 1     || 2015-01-01 ||
  || 3  ||  False  || NULL  || 2015-06-16 ||
  </code></pre>
  
  <p>If something was once valid, it could be invalidated again, but would not reset the Count.</p>
  
  <p>I've tried doing things like:</p>
  
  <pre><code>db.OrderBy(o =&gt; new { o.IsValid, o.Count }).ThenBy(o =&gt; new { o.IsValid, o.CreateDate })
  </code></pre>
  
  <p>or</p>
  
  <pre><code>db.OrderByDescending(o =&gt; o.IsValid).ThenBy(o =&gt; new { o.SortOrder, o.CreateDate })
  </code></pre>
  
  <p>and other combinations, but I don't know how to get the ordering to work as desired.</p>
  
  <p>Anyone able to help?</p>