/*====================================================*/ /// <summary>避免 SqlParameter 參數數量超過 2100 個,將查詢 IN 分次執行。</summary> public static IEnumerable <TSource> WhereIn <TSource, T>(this IQueryable <TSource> source, Expression <Func <TSource, T> > selector, IEnumerable <T> values, int blockSize = 2000) { if (values == null || !values.Any()) { return(Enumerable.Empty <TSource>()); } MethodInfo containsMethod = LambdaUtils.GetMethod(() => values.Contains(default(T))); IEnumerable <TSource> result = values .BulkToList(blockSize) .SelectMany(valueList => { var containsExpr = Expression.Call(containsMethod, Expression.Constant(valueList), selector.Body); return(source.Where(Expression.Lambda <Func <TSource, bool> >(containsExpr, selector.Parameters))); }); return(result); }
public void GetMethod_RunTest3() { MethodInfo method = LambdaUtils.GetMethod(() => new[] { 1 }.Contains(1)); Assert.NotNull(method); }
public void GetMethod_RunTest2() { MethodInfo method = LambdaUtils.GetMethod <IEnumerable <int> >(x => x.Contains(1)); Assert.NotNull(method); }
public void GetMethod_RunTest() { MethodInfo method = LambdaUtils.GetMethod <IEnumerable <int> >(x => x.Any(y => true)); Assert.NotNull(method); }
/// <summary>尋找 Lambda Expression tree 中的 MethodInfo</summary> public static MethodInfo GetMethod(this Expression expr) { return(LambdaUtils.GetMethod(expr)); }