using Microsoft.EntityFrameworkCore; using System; using System.Linq; using System.Linq.Expressions; namespace LifePayment.Domain.Shared; public static class IQueryableExtensions { /// /// 当条件为true时为IQueryable附加where,注:如果条件为true会更新source /// /// /// /// /// /// public static IQueryable WhereIfWithUpdateSource(this IQueryable source, bool condition, Expression> wherePredicate) { if (condition) source = source.Where(wherePredicate); return source; } /// /// 当条件为true时为IQueryable附加include,注:如果条件为true会更新source /// /// /// /// /// /// /// public static IQueryable IncludeIf(this IQueryable source, bool condition, Expression> navigationPropertyPath) where T : class { if (condition) source = source.Include(navigationPropertyPath); return source; } }