Skip to content

Instantly share code, notes, and snippets.

@Jay-Madden
Created January 23, 2022 00:30
Show Gist options
  • Save Jay-Madden/0a87fb4ebf318cc67b4312e51d40eac2 to your computer and use it in GitHub Desktop.
Save Jay-Madden/0a87fb4ebf318cc67b4312e51d40eac2 to your computer and use it in GitHub Desktop.
public static class LinqExtensions
{
public static IQueryable<T> QueryIfElse<T>(this IQueryable<T> query,
Func<bool> predicate,
Func<IQueryable<T>, IQueryable<T>> @if,
Func<IQueryable<T>, IQueryable<T>> @else) =>
predicate() ? @if(query) : @else(query);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment