score:3

Accepted answer

Generally when i have filtering like yours i just do a null check.

 public List<TABLE> Filters(string a, string b, string c ...){
    var query = (from x in context.TABLE
            where 
                  (string.IsNullOrEmpty(a) || x.A ==a) &&
                  (string.IsNullOrEmpty(b) || x.B ==b) &&
                  (string.IsNullOrEmpty(c) || x.C ==b) 
                 select x
    );

   return query.ToList();
  }

With Joins

   var baseQuery = (from x in context.TABLE
            where 
                  (string.IsNullOrEmpty(a) || x.A ==a) &&
            select x
    );

  if(!string.IsNullOrEmpty(b)){
     baseQuery = (
        from item in baseQuery
        join b in context.Bs on item.JoinMeCode equals b.JoinMeCode
        select item

     );
  }

Related Articles