Ejemplo n.º 1
0
        /*====================================================*/

        /// <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);
        }
Ejemplo n.º 2
0
        public void GetGenericMethod_RunTest3()
        {
            MethodInfo method = LambdaUtils.GetGenericMethodDefinition(() => new[] { 1 }.Contains(1));

            Assert.NotNull(method);
        }
Ejemplo n.º 3
0
        public void GetGenericMethod_RunTest2()
        {
            MethodInfo method = LambdaUtils.GetGenericMethodDefinition <IEnumerable <int> >(x => x.Contains(1));

            Assert.NotNull(method);
        }
Ejemplo n.º 4
0
        public void GetGenericMethod_RunTest()
        {
            MethodInfo method = LambdaUtils.GetGenericMethodDefinition <IEnumerable <int> >(x => x.Any(y => true));

            Assert.NotNull(method);
        }
Ejemplo n.º 5
0
        public void GetMethod_RunTest3()
        {
            MethodInfo method = LambdaUtils.GetMethod(() => new[] { 1 }.Contains(1));

            Assert.NotNull(method);
        }
Ejemplo n.º 6
0
        public void FindByType_RunTest(LambdaExpression expr)
        {
            var list = LambdaUtils.FindByType <MemberExpression>(expr);

            Assert.True(list.Count > 0);
        }
Ejemplo n.º 7
0
 /// <summary>尋找 Lambda Expression tree 中的 Generic Definition MethodInfo</summary>
 public static MethodInfo GetGenericMethodDefinition(this Expression expr)
 {
     return(LambdaUtils.GetGenericMethodDefinition(expr));
 }
Ejemplo n.º 8
0
 /// <summary>尋找 Lambda Expression tree 中的 MethodInfo</summary>
 public static MethodInfo GetMethod(this Expression expr)
 {
     return(LambdaUtils.GetMethod(expr));
 }
Ejemplo n.º 9
0
 /// <summary>尋找 Lambda Expression tree 中的 PropertyInfo</summary>
 public static PropertyInfo GetProperty(this LambdaExpression expr)
 {
     return(LambdaUtils.GetProperty(expr));
 }
Ejemplo n.º 10
0
 /// <summary>尋找 Lambda Expression tree 中的 MemberInfo</summary>
 public static MemberInfo GetMember(this LambdaExpression expr)
 {
     return(LambdaUtils.GetMember(expr));
 }
Ejemplo n.º 11
0
 /// <summary>尋找 Lambda Expression tree 中指定類型</summary>
 public static List <T> FindByType <T>(this Expression expr) where T : Expression
 {
     return(LambdaUtils.FindByType <T>(expr));
 }