title: Linq Ternary Code Better Solution
body: <p>I have this code a developer wrote. I think its horrible and shouldnt be necessary</p>
  
  <pre><code>value = s.Businesses.SelectMany(
      x =&gt; x.Payments.Where(
          w =&gt; w.total != 0 &amp;&amp; 
          !w.jobId.HasValue &amp;&amp; 
          w.createdAt &gt;= Utility.monthS 
          &amp;&amp; w.createdAt &lt;= Utility.monthE)
      ).Any() ? 
          s.Businesses.SelectMany(
              x =&gt; x.Payments.Where(
                  w =&gt; w.total != 0 &amp;&amp; 
                  !w.jobId.HasValue &amp;&amp; 
                  w.createdAt &gt;= Utility.monthS 
                  &amp;&amp; w.createdAt &lt;= Utility.monthE)
              ).Sum(su =&gt; su.quantity) 
          : 0;
  </code></pre>
  
  <p>The reason it does the <code>.Any</code> before the <code>Sum</code> is that records with no values end up getting null values and causing errors. </p>
  
  <p>Is there a better best practice way of writing this.</p>