Hi folks,
i have the following linq extension method, which returns an IEnumerable. This means, that this piece of code ends up hitting the DB, before the rest of the linq statement has been finished.
Is it possible to refactor this so it returns an IQueryable instead?
public static IEnumerable<TSource> WhereIf<TSource>
(this IEnumerable<TSource> source, bool condition,
Func<TSource, bool> predicate)
{
return condition ? source.Where(predicate) : source;
}