Skip to content

Commit

Permalink
add whereif
Browse files Browse the repository at this point in the history
  • Loading branch information
liuliang-wt committed May 15, 2021
1 parent bdc4550 commit 440f093
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/WalkingTec.Mvvm.Core/Extensions/DCExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,15 @@ public static IQueryable<T> CheckNull<T>(this IQueryable<T> baseQuery, Expressio
return baseQuery.Where(Expression.Lambda<Func<T, bool>>(Expression.Equal(peid, Expression.Constant(null)), pe));
}


/// <summary>
/// val不为空时,附加查询条件
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="S"></typeparam>
/// <param name="baseQuery"></param>
/// <param name="val"></param>
/// <param name="where"></param>
/// <returns></returns>
public static IQueryable<T> CheckWhere<T, S>(this IQueryable<T> baseQuery, S val, Expression<Func<T, bool>> where)
{
if (val == null)
Expand All @@ -690,6 +698,23 @@ public static IQueryable<T> CheckWhere<T, S>(this IQueryable<T> baseQuery, S val
}
}

/// <summary>
/// 条件为true时,附加查询条件
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="baseQuery"></param>
/// <param name="val">bool?</param>
/// <param name="where"></param>
/// <returns></returns>
public static IQueryable<T> WhereIf<T>(this IQueryable<T> baseQuery, bool? val, Expression<Func<T, bool>> where)
{
if (val == null || val == false)
{
return baseQuery;
}
return baseQuery.Where(where);
}

public static IQueryable<T> CheckEqual<T>(this IQueryable<T> baseQuery, string val, Expression<Func<T, string>> field)
{
if (val == null || val == "")
Expand Down

0 comments on commit 440f093

Please sign in to comment.