using System;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using System.Linq.Expressions;
namespace Start.Server {
/// Extension methods for LINQ queries
public static class LinqExtensions {
///
/// If is true, then returns query.Where(expression).
/// Otherwise returns the unchanged.
///
/// The query to potentially apply the expression to
///
/// Determines whether or not the expression should be applied
///
/// A function to test each element
public static IQueryable IfWhere(this IQueryable query, bool condition,
Expression> expression) {
if (condition)
return query.Where(expression);
return query;
}
///
/// If the is true, apply the to
/// the query, otherwise return the query unchanged.
///
/// The 's type
/// The query to potentially transform
///
/// If true, apply the to the
///
///
/// A function to apply to the if the
/// is true
///
public static IQueryable If(this IQueryable query, bool condition,
Func, IQueryable> transform) {
if (condition)
return transform(query);
return query;
}
}
}