예제 #1
0
        private static IQueryable LoadToMemory(Type elementType, IQueryable[] sources, IEnumerable <Expression> predicates = null)
        {
            MethodInfo addRangeToListMethodInfo = DataFacadeReflectionCache.List_AddRangeMethodInfo(elementType);
            MethodInfo toListMethodInfo         = DataFacadeReflectionCache.Enumerable_ToList(elementType);

            IList list = DataFacadeReflectionCache.List_New(elementType);

            foreach (IQueryable query in sources)
            {
                IQueryable filteredQuery = ApplyPredicates(query, elementType, predicates);

                var subList = toListMethodInfo.Invoke(null, new object[] { filteredQuery });

                addRangeToListMethodInfo.Invoke(list, new object[] { subList });
            }

            MethodInfo asQueryableMethodInfo = DataFacadeReflectionCache.Queryable_AsQueryableMethodInfo(elementType);

            object listedDataAsQueryable = asQueryableMethodInfo.Invoke(null, new object[] { list });


            if (RuntimeInformation.IsDebugBuild)
            {
                if (list.Count > 500)
                {
                    Log.LogInformation("DataFacadeQuery", list.Count + " rows in a single query. Element type:" + elementType.FullName);
                }
            }

            return((IQueryable)listedDataAsQueryable);
        }
예제 #2
0
        public static IQueryable <T> GetQueryableByData <T>(T data, bool ignoreVersioning)
            where T : class, IData
        {
            LambdaExpression whereLambdaExpression = GetWhereLambdaExpression(data, ignoreVersioning);

            IQueryable queryable = DataFacade.GetData(data.DataSourceId.InterfaceType);

            Expression whereExpression = ExpressionCreator.Where(queryable.Expression, whereLambdaExpression);

            MethodInfo methodInfo = DataFacadeReflectionCache.GetCreateQueryMethodInfo(data.DataSourceId.InterfaceType);

            return((IQueryable <T>)methodInfo.Invoke(queryable.Provider, new object[] { whereExpression }));
        }
예제 #3
0
        private static IQueryable Take(IQueryable[] sources, int count, IEnumerable <Expression> predicates = null)
        {
            Type elementType = GetElementType(sources);

            MethodInfo addRangeToListMethodInfo = DataFacadeReflectionCache.List_AddRangeMethodInfo(elementType);

            Type listType   = typeof(List <>).MakeGenericType(elementType);
            var  List_Count = listType.GetProperty("Count");
            var  list       = Activator.CreateInstance(listType);

            int taken = 0;

            foreach (IQueryable query in sources)
            {
                IQueryable filteredQuery = ApplyPredicates(query, elementType, predicates);

                int elementsToTake = count - taken;

                var subList = Queryable_Take.MakeGenericMethod(elementType).Invoke(null, new object[] { filteredQuery, elementsToTake });

                addRangeToListMethodInfo.Invoke(list, new object[] { subList });

                taken = (int)List_Count.GetValue(list, null);

                if (taken == count)
                {
                    break;
                }
            }

            MethodInfo asQueryableMethodInfo = DataFacadeReflectionCache.Queryable_AsQueryableMethodInfo(elementType);

            object listedDataAsQueryable = asQueryableMethodInfo.Invoke(null, new [] { list });

            return((IQueryable)listedDataAsQueryable);
        }
예제 #4
0
        public object Execute(Expression expression)
        {
            MethodInfo methodInfo = DataFacadeReflectionCache.GetDataFacadeQueryableExecuteMethodInfo(typeof(T), expression.Type);

            return(methodInfo.Invoke(this, new object[] { expression }));
        }
예제 #5
0
        IEnumerator IEnumerable.GetEnumerator()
        {
            MethodInfo methodInfo = DataFacadeReflectionCache.GetDataFacadeQueryableGetEnumeratorMethodInfo(typeof(T));

            return((IEnumerator)methodInfo.Invoke(this, null));
        }