title: Dynamic Linq Build Where Clause many Parameters
body: <p>I will explain my Problem </p>
  
  <p>so Firstly, I use Predicates Linq for Build Where clause dynamically.
  I have to build dynamically because I don't know how many parameters will come. Let me give an example. For the A column can be one parameters however, for the B column can be 2 parameters like either value 'Gas' or 'Oil' which select but that's big problem I can not combine for these 2 column correctly.
  So as a result, this code work but It return 0 Items. But there are I know.</p>
  
  <pre><code>public List&lt;CarEntity&gt; GetSearchByKCriteria(int cityId, List&lt;string&gt; fuelType, List&lt;string&gt; gearType, List&lt;string&gt; budget,
          List&lt;string&gt; caroser, List&lt;string&gt; enginePower)
      {
          Expression&lt;Func&lt;Car, bool&gt;&gt; query = null;
          Expression&lt;Func&lt;Car, bool&gt;&gt; combine = null;
  
          foreach (var bud in budget)
          {
              if (budget.Count &gt;= 1)
              {
                  if (bud == "1")
                  {
                      if (budget.Count &gt; 1)
                      {
                          query = car =&gt; car.Budget &gt;= 20000 &amp;&amp; car.Budget &lt;= 34999;
                      }
                      else
                      {
                          query = car =&gt; car.Budget &gt;= 20000 &amp;&amp; car.Budget &lt;= 34999;
                      }
  
                  }
                  else if (bud == "2")
                  {
  
                      if (query != null)
                      {
                          combine = car =&gt; (car.Budget &gt;= 35000 &amp;&amp; car.Budget &lt;= 49999);
                          query = query.Or(combine);
  
                      }
                      else
                      {
                          query = car =&gt; car.Budget &gt;= 35000 &amp;&amp; car.Budget &lt;= 49999;
  
                      }
                  }
              }
          }
          foreach (var caros in caroser)
          {
              if (caros != "-1" &amp;&amp; !string.IsNullOrEmpty(caros))
              {
                  if (query != null)
                  {
                      if (query.Expand().ToString().ToLower().Contains("karoser"))
                      {
                          combine = car =&gt; (car.Karoser == caros);
                          query = query.And(combine);
  
                      }
                      else
                      {
                          combine = car =&gt; car.Karoser == caros;
                          query = query.And(combine);
  
                      }
  
                  }
                  else
                  {
                      query = car =&gt; car.Karoser == caros;
                  }
              }
          }
          foreach (var fuel in fuelType)
          {
              if (fuel != "-1" &amp;&amp; !string.IsNullOrEmpty(fuel))
              {
                  if (query != null)
                  {
                      if (query.Expand().ToString().ToLower().Contains("yakituru"))
                      {
                          combine = car =&gt; (car.YakitTuru==fuel);
                          query = query.Or(combine);
  
                      }
                      else
                      {
                          combine = car =&gt; car.YakitTuru == fuel;
                          query = query.And(combine);
  
                      }
  
                  }
                  else
                  {
                      query = car =&gt; car.YakitTuru == fuel;
                  }
              }
          }
          foreach (var gear in gearType)
          {
              if (gear!="-1"&amp;&amp; !string.IsNullOrEmpty(gear))
              {
                  if (query != null)
                  {
                      if (query.Expand().ToString().ToLower().Contains("sanzimantipi"))
                      {
                          combine = car =&gt; (car.SanzimanTipi == gear);
                          query = query.Or(combine);
  
                      }
                      else
                      {
                          combine = car =&gt; car.SanzimanTipi == gear;
                          query = query.And(combine);
  
                      }
  
                  }
                  else
                  {
                      query = car =&gt; car.SanzimanTipi == gear;
                  } 
              }
          }
          foreach (var engine in enginePower)
          {
              if (enginePower.Count &gt;= 1)
              {
                  if (engine == "1")
                  {
                      if (query != null)
                      {
                          if (query.Expand().ToString().ToLower().Contains("silindirhacmi"))
                          {
                              combine = car =&gt; (car.SilindirHacmi &gt;= 0 &amp;&amp; car.SilindirHacmi &lt;= 1600);
                              query = query.Or(combine);
  
                          }
                          else
                          {
                              combine = car =&gt; (car.SilindirHacmi &gt;= 0 &amp;&amp; car.SilindirHacmi &lt;= 1600);
                              query = query.And(combine);
  
                          }
  
                      }
                      else
                      {
                          query = car =&gt; car.SilindirHacmi &gt;= 0 &amp;&amp; car.SilindirHacmi &lt;= 1600;
                      }
                  }
  
                  if (engine == "3")
                  {
                      if (query != null)
                      {
                          if (query.Expand().ToString().ToLower().Contains("silindirhacmi"))
                          {
                              combine = car =&gt; (car.SilindirHacmi &gt;= 1601 &amp;&amp; car.SilindirHacmi &lt;= 1800);
                              query = query.Or(combine);
  
                          }
                          else
                          {
                              combine = car =&gt; (car.SilindirHacmi &gt;= 1601 &amp;&amp; car.SilindirHacmi &lt;= 1800);
                              query = query.And(combine);
  
                          }
  
                      }
                      else
                      {
                          query = car =&gt; car.SilindirHacmi &gt;= 1601 &amp;&amp; car.SilindirHacmi &lt;= 1800;
                      }
                  }
  
          }
  
          using (var context = DataContextFactory.CreateContext())
          {
  
              var result = (from fkCar in context.Car.Where(query)
                            join pkCarBrand in context.CarBrand on fkCar.Marka equals pkCarBrand.ID
                            where fkCar.IsActive == true
  
                            select new
                            {
                                entity = fkCar,
                                joinEntity = pkCarBrand
                            });
              List&lt;CarEntity&gt; theCarList = new List&lt;CarEntity&gt;();
              foreach (var item in result)
              {
                  CarEntity theEntity = Mapper.Map(item.entity);
                  theEntity.CarBrand = Mapper.Map(item.joinEntity);
                  theCarList.Add(theEntity);
  
              }
              return theCarList;
          }
      }
  </code></pre>
  
  <p>So thanks for reply,</p>