Filter Collection by Multiple Criteria I want to the user to filter a list of receipts by various criteria. Just the regular, an empty filter should show all items, an entry in customer should show all receipts from that customer and an additional entry in date should show all entries from said customer on the given date. I have the feeling, my if else apprach is not the best way, since with 4 criteria I'm already at 16 branches, not speak of 5, 6, or 7 criteria.

What is the most elegant way to achieve this. 

Model:

class customer
{

    public int ID { get; set; }

    public string Name { get; set; }

}

class receipt
{

    public int ID { get; set; }

    public string Number { get; set; }

    public DateTime Date { get; set; }

    public double Amount { get; set; }

    public customer Customer { get; set; }

}


Viewmodel

class receiptViewModel
{

    ObservableCollection&lt;receipt&gt; ReceiptList { get; set; }

    List&lt;receipt&gt; ReceiptListView { get; set; }

    private string filter;

    public string Filter
    {
        get { return filter; }
        set
        {

            filter = value;

            if (number != null &amp;&amp; date == null &amp;&amp; customer &amp;&amp; null)
            {
                ReceiptListView = ReceiptList.Where(x =&gt; x.Number.Contains(number)).ToList();
            }
            else if (number != null &amp;&amp; date != null &amp;&amp; customer &amp;&amp; null)
            {
                ReceiptListView = ReceiptList.Where(x =&gt; x.Number.Contains(number) &amp;&amp; x.Date === date).ToList();
            }
            //aso aso aso
          }
    }
You can build the LINQ query in several steps by appending new where clauses

IEnumerable&lt;receipt&gt; query = ReceiptList;
if (customer != null) {
    query = query.Where(x =&gt; x.CustomerId == customer.ID);
}
if (number != null) {
    query = query.Where(x =&gt; x.Number.Contains(number));
}
if (date != null) {
    query = query.Where(x =&gt; x.Date == date);
}
...
ReceiptListView = query.ToList();


This reduces the complexity from O(2ⁿ) to O(n)