private List <Dictionary <string, object> > LoadDataCollection(ExpressionMetadataChain chain)
        {
            var selectQuery = ModelQueryBuilder.BuildSelectQuery(chain);
            var response    = _dataProvider.GetItems(selectQuery);

            return(response != null && response.Success
                                ? response.Items
                                : new List <Dictionary <string, object> >());
        }
        private T ApplyScalarProjector <T>(List <object> sourceItems, ExpressionMetadataChain chain)
        {
            var notAppliedChainItems = chain.Items.Where(x => !x.IsAppliedToQuery).ToList();

            if (!notAppliedChainItems.Any())
            {
                return(sourceItems.Any() ? (T)sourceItems.First() : default(T));
            }
            var method = RepositoryReflectionUtilities.GetGenericMethod(this.GetType(), "ApplyTypedScalarProjector", typeof(T),
                                                                        notAppliedChainItems.First().InputDtoType.Type);

            return((T)method.Invoke(this, new object[] { sourceItems, chain }));
        }
示例#3
0
        public static SelectQuery BuildSelectQuery(ExpressionMetadataChain expressionMetadataChain)
        {
            if (expressionMetadataChain.IsEmpty())
            {
                var defaultConfig = GenerateModelQueryBuildConfig(expressionMetadataChain.LastValueType);
                return(defaultConfig.SelectQuery);
            }

            var modelType = expressionMetadataChain.GetModelType();
            var config    = GenerateModelQueryBuildConfig(modelType);

            expressionMetadataChain.Items.TakeWhile(x => ApplyExpressionChainItemOnSelectQuery(x, config)).ToList();
            OptimizeFilters(config.SelectQuery.Filters);
            return(config.SelectQuery);
        }
        private T ApplyTypedScalarProjector <T, TItem>(List <object> rawSourceItems, ExpressionMetadataChain chain)
        {
            var        sourceItems      = rawSourceItems.Select(x => (TItem)x).ToList();
            Expression sourceExpression = Expression.Constant(sourceItems.AsQueryable());

            chain.Items.Where(x => !x.IsAppliedToQuery).ForEach(x => {
                if (x.Expression.Arguments.Count == 1)
                {
                    sourceExpression = Expression.Call(null, x.Expression.Method, sourceExpression);
                }
                else if (x.Expression.Arguments.Count == 2)
                {
                    sourceExpression = Expression.Call(null, x.Expression.Method, sourceExpression,
                                                       x.Expression.Arguments.Skip(1).First());
                }
                else
                {
                    throw new System.NotSupportedException();
                }
            });

            return((T)Expression.Lambda(sourceExpression).Compile().DynamicInvoke());
        }
        private List <BaseModel> LoadModelCollection(List <Dictionary <string, object> > dataCollection, ExpressionMetadataChain chain)
        {
            var method = RepositoryReflectionUtilities.GetGenericMethod(GetType(),
                                                                        "LoadTypedModelCollection", chain.GetModelType());
            var models = (List <BaseModel>)method?.Invoke(this, new object[] { dataCollection });

            return(models);
        }
        private IEnumerable <T> ApplyTypedCollectionProjector <T, TItem>(IEnumerable <object> rawSourceItems, ExpressionMetadataChain chain)
        {
            var        sourceItems      = rawSourceItems.Select(x => (TItem)x).ToList();
            Expression sourceExpression = Expression.Constant(sourceItems.AsQueryable());

            chain.Items.Where(x => !x.IsAppliedToQuery).ForEach(x => {
                sourceExpression = Expression.Call(null, x.Expression.Method, sourceExpression,
                                                   x.Expression.Arguments.Skip(1).First());
            });

            return((IEnumerable <T>)Expression.Lambda(sourceExpression).Compile().DynamicInvoke());
        }
        private IEnumerable <T> ApplyCollectionProjector <T>(IReadOnlyCollection <object> sourceItems, ExpressionMetadataChain chain)
        {
            var notAppliedChainItems = chain.Items.Where(x => !x.IsAppliedToQuery).ToList();

            if (notAppliedChainItems.Any())
            {
                var method = RepositoryReflectionUtilities.GetGenericMethod(this.GetType(), "ApplyTypedCollectionProjector", typeof(T),
                                                                            notAppliedChainItems.First().InputDtoType.Type);
                return((IEnumerable <T>)method.Invoke(this, new object[] { sourceItems, chain }));
            }
            return(sourceItems.Select(x => (T)x).AsEnumerable());
        }