QueryExtensions IsBtwn
Δημοσιεύτηκε: Δευ Φεβ 07, 2022 8:17 pm
public static IEnumerable<TSource> IsBtwn<TSource, TKey>(this IEnumerable<TSource> source, Expression<Func<TSource, TKey?>> field, TKey? frm, TKey? to) where TKey : struct, IComparable<TKey> => IsBtwn(source, field, frm, to, true);
public static IEnumerable<TSource> IsBtwn<TSource, TKey>(this IEnumerable<TSource> source, Expression<Func<TSource, TKey?>> field, TKey? frm, TKey? to, bool aplly) where TKey : struct, IComparable<TKey> {
if (!aplly) return source;
Expression fldEx = Expression.Invoke(field, field.Parameters);
var frmEx = Kexpression.GreaterThanOrEqualNullable(fldEx, Expression.Constant(frm));
var toEx = Kexpression.LessThanOrEqualNullable(fldEx, Expression.Constant(to));
Expression andEx = Expression.And(frmEx, toEx);
var lambda = Expression.Lambda<Func<TSource, bool>>(andEx, field.Parameters).Compile();
return source.Where(lambda);
}
public static IEnumerable<TSource> IsBtwn<TSource, TKey>(this IEnumerable<TSource> source, Expression<Func<TSource, TKey>> field, TKey frm, TKey to) where TKey : IComparable<TKey> => IsBtwn(source, field, frm, to, true);
public static IEnumerable<TSource> IsBtwn<TSource, TKey>(this IEnumerable<TSource> source, Expression<Func<TSource, TKey>> field, TKey frm, TKey to, bool aplly) where TKey : IComparable<TKey> {
if (!aplly) return source;
Expression fldEx = Expression.Invoke(field, field.Parameters);
Expression frmEx = Expression.GreaterThanOrEqual(fldEx, Expression.Constant(frm));
Expression toEx = Expression.LessThanOrEqual(fldEx, Expression.Constant(to));
Expression andEx = Expression.And(frmEx, toEx);
var lambda = Expression.Lambda<Func<TSource, bool>>(andEx, field.Parameters).Compile();
return source.Where(lambda);
}
public static IQueryable<TSource> IsBtwn<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey?>> field, TKey? frm, TKey? to) where TKey : struct, IComparable<TKey> => IsBtwn(source, field, frm, to, true);
public static IQueryable<TSource> IsBtwn<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey?>> field, TKey? frm, TKey? to, bool aplly) where TKey : struct, IComparable<TKey> {
if (!aplly) return source;
Expression fldEx = Expression.Invoke(field, field.Parameters);
var frmEx = Kexpression.GreaterThanOrEqualNullable(fldEx, Expression.Constant(frm));
var toEx = Kexpression.LessThanOrEqualNullable(fldEx, Expression.Constant(to));
Expression andEx = Expression.And(frmEx, toEx);
var lambda = Expression.Lambda<Func<TSource, bool>>(andEx, field.Parameters);
return source.Where(lambda);
}
public static IQueryable<TSource> IsBtwn<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey>> field, TKey frm, TKey to) where TKey : IComparable<TKey> => IsBtwn(source, field, frm, to, true);
public static IQueryable<TSource> IsBtwn<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey>> field, TKey frm, TKey to, bool aplly) where TKey : IComparable<TKey> {
if (!aplly) return source;
Expression fldEx = Expression.Invoke(field, field.Parameters);
Expression frmEx = Expression.GreaterThanOrEqual(fldEx, Expression.Constant(frm));
Expression toEx = Expression.LessThanOrEqual(fldEx, Expression.Constant(to));
Expression andEx = Expression.And(frmEx, toEx);
var lambda = Expression.Lambda<Func<TSource, bool>>(andEx, field.Parameters);
return source.Where(lambda);
}
public static IEnumerable<TSource> IsBtwn<TSource, TKey>(this IEnumerable<TSource> source, Expression<Func<TSource, TKey?>> field, TKey? frm, TKey? to, bool aplly) where TKey : struct, IComparable<TKey> {
if (!aplly) return source;
Expression fldEx = Expression.Invoke(field, field.Parameters);
var frmEx = Kexpression.GreaterThanOrEqualNullable(fldEx, Expression.Constant(frm));
var toEx = Kexpression.LessThanOrEqualNullable(fldEx, Expression.Constant(to));
Expression andEx = Expression.And(frmEx, toEx);
var lambda = Expression.Lambda<Func<TSource, bool>>(andEx, field.Parameters).Compile();
return source.Where(lambda);
}
public static IEnumerable<TSource> IsBtwn<TSource, TKey>(this IEnumerable<TSource> source, Expression<Func<TSource, TKey>> field, TKey frm, TKey to) where TKey : IComparable<TKey> => IsBtwn(source, field, frm, to, true);
public static IEnumerable<TSource> IsBtwn<TSource, TKey>(this IEnumerable<TSource> source, Expression<Func<TSource, TKey>> field, TKey frm, TKey to, bool aplly) where TKey : IComparable<TKey> {
if (!aplly) return source;
Expression fldEx = Expression.Invoke(field, field.Parameters);
Expression frmEx = Expression.GreaterThanOrEqual(fldEx, Expression.Constant(frm));
Expression toEx = Expression.LessThanOrEqual(fldEx, Expression.Constant(to));
Expression andEx = Expression.And(frmEx, toEx);
var lambda = Expression.Lambda<Func<TSource, bool>>(andEx, field.Parameters).Compile();
return source.Where(lambda);
}
public static IQueryable<TSource> IsBtwn<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey?>> field, TKey? frm, TKey? to) where TKey : struct, IComparable<TKey> => IsBtwn(source, field, frm, to, true);
public static IQueryable<TSource> IsBtwn<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey?>> field, TKey? frm, TKey? to, bool aplly) where TKey : struct, IComparable<TKey> {
if (!aplly) return source;
Expression fldEx = Expression.Invoke(field, field.Parameters);
var frmEx = Kexpression.GreaterThanOrEqualNullable(fldEx, Expression.Constant(frm));
var toEx = Kexpression.LessThanOrEqualNullable(fldEx, Expression.Constant(to));
Expression andEx = Expression.And(frmEx, toEx);
var lambda = Expression.Lambda<Func<TSource, bool>>(andEx, field.Parameters);
return source.Where(lambda);
}
public static IQueryable<TSource> IsBtwn<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey>> field, TKey frm, TKey to) where TKey : IComparable<TKey> => IsBtwn(source, field, frm, to, true);
public static IQueryable<TSource> IsBtwn<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey>> field, TKey frm, TKey to, bool aplly) where TKey : IComparable<TKey> {
if (!aplly) return source;
Expression fldEx = Expression.Invoke(field, field.Parameters);
Expression frmEx = Expression.GreaterThanOrEqual(fldEx, Expression.Constant(frm));
Expression toEx = Expression.LessThanOrEqual(fldEx, Expression.Constant(to));
Expression andEx = Expression.And(frmEx, toEx);
var lambda = Expression.Lambda<Func<TSource, bool>>(andEx, field.Parameters);
return source.Where(lambda);
}