/*====================================================*/ /// <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 GetGenericMethod_RunTest3() { MethodInfo method = LambdaUtils.GetGenericMethodDefinition(() => new[] { 1 }.Contains(1)); Assert.NotNull(method); }
public void GetGenericMethod_RunTest2() { MethodInfo method = LambdaUtils.GetGenericMethodDefinition <IEnumerable <int> >(x => x.Contains(1)); Assert.NotNull(method); }
public void GetGenericMethod_RunTest() { MethodInfo method = LambdaUtils.GetGenericMethodDefinition <IEnumerable <int> >(x => x.Any(y => true)); Assert.NotNull(method); }
public void GetMethod_RunTest3() { MethodInfo method = LambdaUtils.GetMethod(() => new[] { 1 }.Contains(1)); Assert.NotNull(method); }
public void FindByType_RunTest(LambdaExpression expr) { var list = LambdaUtils.FindByType <MemberExpression>(expr); Assert.True(list.Count > 0); }
/// <summary>尋找 Lambda Expression tree 中的 Generic Definition MethodInfo</summary> public static MethodInfo GetGenericMethodDefinition(this Expression expr) { return(LambdaUtils.GetGenericMethodDefinition(expr)); }
/// <summary>尋找 Lambda Expression tree 中的 MethodInfo</summary> public static MethodInfo GetMethod(this Expression expr) { return(LambdaUtils.GetMethod(expr)); }
/// <summary>尋找 Lambda Expression tree 中的 PropertyInfo</summary> public static PropertyInfo GetProperty(this LambdaExpression expr) { return(LambdaUtils.GetProperty(expr)); }
/// <summary>尋找 Lambda Expression tree 中的 MemberInfo</summary> public static MemberInfo GetMember(this LambdaExpression expr) { return(LambdaUtils.GetMember(expr)); }
/// <summary>尋找 Lambda Expression tree 中指定類型</summary> public static List <T> FindByType <T>(this Expression expr) where T : Expression { return(LambdaUtils.FindByType <T>(expr)); }