Personally, I'd find having this broken up to be simpler:
IEnumerable<Quote> filteredList = allQuotes;
// If using EF or LINQ to SQL, use: IQueryable<Quote> filteredList = allQuotes;
if (drpOwners.SelectedValue != ALL)
filteredList = filteredList.Where(x => x.SalesRepFullName == drpOwners.SelectedValue);
if (drpCompanyName.SelectedValue != ALL)
filteredList = filteredList.Where(x => x.CompanyName == drpCompanyName.SelectedValue);
// More conditions as needed
This really isn't any longer, and it's far simpler to follow.
If you really wanted to be able to write this as a "one-liner", you could make an extension method to build the query. For example, if using Entity Framework:
static IQueryable<T> AddCondition(this IQueryable<T> queryable, Func<bool> predicate, Expression<Func<T,bool>> filter)
{
if (predicate())
return queryable.Where(filter);
else
return queryable;
}
This would then let you write this as:
var filteredList = allQuotes
.AddCondition(() => drpOwners.SelectedValue != ALL, x => x.SalesRepFullName == drpOwners.SelectedValue)
.AddCondition(() => drpCompanyName.SelectedValue != ALL, x.CompanyName == drpCompanyName.SelectedValue);
You could, of course, take this even further, and make a version that hard-wires the predicate to check a combo box against "ALL", making the predicate shorter (just the combo box).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…