title: Linq where clause "if item is not null, evaluate, otherwise, get all data"
body: <p>I'm trying to implement a filter form on a web client which could have any number of items either filled out or empty.  My WebAPI method will take a model that is all of the properties of the form, it would be like:</p>
  
  <pre><code>RequisitionType (enum: RequisitionType.RequisitionedBy, RequisitionType.CreatedBy)
  Vendor (string or null)
  Plant (string or null)
  CompanyCode (string or null)
  CreatedFrom (datetime)
  CreatedTo (datetime)
  </code></pre>
  
  <p>How could I implement a linq query without have many crazy <code>if (condition) { filter }</code>?</p>
  
  <p>I've tried something like this, where I first check if the filter has a value and if it does I will compare the field to that value, otherwise I'll compare the field to itself, but the compiler isn't allowing that.</p>
  
  <p>In the example below, <code>model</code> is what's passed to the controller from the client.</p>
  
  <pre><code>var data =  logic.GetPurchaseReqs()
              .Where(pr =&gt; {
                  model.RequisitionType == RequisitionType.RequisitionedBy ? pr.PrReqId.ToUpper() == model.Username.ToUpper() : pr.PrReqId.ToUpper() == pr.PrReqId.ToUpper()
                  &amp;&amp; model.RequisitionType == RequisitionType.CreatedBy ? pr.PrCreId.ToUpper() == model.Username.ToUpper() : pr.PrCreId.ToUpper() == pr.PrCreId.ToUpper()
                  &amp;&amp; model.Vendor != null ? pr.Vendor == model.Vendor : pr.Vendor == pr.Vendor
                  [etc...]
              })
              .ToList();
  </code></pre>