title: Exclude null or empty string value from lambda expression
body: <p>In my app in <code>GetAll</code> function I have a parameter which is called (<code>CustomerModel</code>). I use it to do some filtering over the query and I used specification pattern to avoid using <code>if-else</code> :</p>
  
  <pre><code>    public async Task&lt;List&lt;CustomerModel&gt;&gt; GetAllAsync(CustomerModel customer, Order order = Order.Ascending, int pageIndex = 1, int pageSize = int.MaxValue)
      {
          var skip = (pageIndex - 1) * pageSize;
  
          var filter = new CustomerNameSpecification(customer)
              .And(new CustomerNoSpecification(customer))
              .And(new CustomerCompanySpecification(customer))
              .And(new CustomerPhoneSpecification(customer))
              .And(new CustomerEmailSpecification(customer))
              .And(new CustomerAddressSpecification(customer))
              .Take(pageSize)
              .Skip(skip);
  
          var orderSpecification = new CustomerOrderSpecification(order);
  
          return await _customerRepository.GetAllAsync(filter, orderSpecification);
      }
  </code></pre>
  
  <p>And for instance one of the specification objects (<code>CustomerNameSpecification</code>) :</p>
  
  <pre><code>public class CustomerNameSpecification : Specification&lt;Customer&gt;
  {
      public CustomerModel Customer { get; set; }
  
      public CustomerNameSpecification(CustomerModel customerModel)
      {
          Customer = customerModel;
      }
  
      public override Expression&lt;Func&lt;Customer, bool&gt;&gt; AsExpression()
      {
          return customerFiler =&gt;
              customerFiler.Name.Contains(Customer.Name);
      }
   }
  </code></pre>
  
  <blockquote>
    <p>UPDATE</p>
  </blockquote>
  
  <p>And operation in the specification pattern:</p>
  
  <pre><code>public class AndSpecification&lt;T&gt; : Specification&lt;T&gt; 
      where T : class
  {
      private readonly ISpecification&lt;T&gt; _left;
      private readonly ISpecification&lt;T&gt; _right;
  
      public AndSpecification(ISpecification&lt;T&gt; left, ISpecification&lt;T&gt; right)
      {
          _left = left;
          _right = right;
      }
  
      public override Expression&lt;Func&lt;T, bool&gt;&gt; AsExpression()
      {
          var leftExpression = _left.AsExpression();
          var rightExpression = _right.AsExpression();
  
          var parameter = leftExpression.Parameters.Single();
          var body = Expression.AndAlso(leftExpression.Body, SpecificationParameterRebinder.ReplaceParameter(rightExpression.Body, parameter));
  
          return Expression.Lambda&lt;Func&lt;T, bool&gt;&gt;(body, parameter);
      }
    }
  }
  </code></pre>
  
  <p>And those chains make a lambda expression at the end and repository uses it to filter the query.</p>
  
  <p>This solution works fine when each field of <code>CustomerModel</code> has a value, But it does not work even if one property has a null or empty value.</p>
  
  <p>How can I fix this problem and exclude lambda expression where I have a null or empty string value?</p>