title: Ternary operator add or not where conditions in linq
body: <p>I have this query:</p>
  <pre><code>if(!string.IsNullOrEmpty(code) &amp;&amp; !string.IsNullOrEmpty(name))
  {
      return this.context.Table.Where(
           x =&gt; EF.Functions.Contains(x.Code, $&quot;\&quot;{code}\&quot;&quot;) 
           &amp;&amp; EF.Functions.Contains(x.Name, $&quot;\&quot;{name}\&quot;&quot;));
  }
  else if(string.IsNullOrEmpty(code) &amp;&amp; !string.IsNullOrEmpty(name))
  {
      return this.context.Table.Where(x =&gt; EF.Functions.Contains(x.Name, $&quot;\&quot;{name}\&quot;&quot;));
  }
  else
  {
      return this.context.Table.Where(x =&gt; EF.Functions.Contains(x.Code, $&quot;\&quot;{code}\&quot;&quot;));
  }
  </code></pre>
  <p>I tried to do it again using the ternary operators then check if the string is not null or empty and if so add the where clause or not
  I tried such a thing but obviously expects that after the &quot;?&quot; there is the alternative of &quot;:&quot;</p>
  <pre><code>return this.context.Table.Where(
      x =&gt; !string.IsNullOrEmpty(code) 
      ? EF.Functions.Contains(x.Code, $&quot;\&quot;{code}\&quot;&quot;) 
      &amp;&amp; !string.IsNullOrEmpty(name) 
      ? EF.Functions.Contains(x.Name, $&quot;\&quot;{name}\&quot;&quot;));
  </code></pre>
  <p>Since unlike the example in my case I have to check 8 different input parameters that if not passed must not be used in the where for the controls, I wanted to avoid filling the code of many if cases and rewriting the query n times for the different combinations, is there a way or should I resign myself?</p>