コード例 #1
0
        public IEnumerable <TResult> ExecuteCollection <TResult>(QueryModel queryModel)
        {
            lock (_lock)
            {
                IEnumerable <TResult> results = null;

                if (SpQueryArgs == null)
                {
                    return(Enumerable.Empty <TResult>());
                }

                var spView = GetView(queryModel);

                if (SpQueryArgs.SkipResult)
                {
                    return(Enumerable.Empty <TResult>());
                }

                var entities = _manager.GetEntities(spView);

                foreach (var resultOperator in queryModel.ResultOperators)
                {
                    if (resultOperator is ReverseResultOperator)
                    {
                        entities = entities.Reverse();
                    }
                }

                if (typeof(TEntity).IsAssignableFrom(typeof(TResult)))
                {
                    results = entities.Cast <TResult>();
                }
                else if (typeof(TResult) == typeof(bool))
                {
                    results = entities.Select(result => result.Id > 0).Cast <TResult>();
                }
                return(results);
            }
        }
コード例 #2
0
        public IEnumerable <TResult> ExecuteCollection <TResult>(QueryModel queryModel)
        {
            lock (_lock)
            {
                if (SpQueryArgs == null)
                {
                    return(Enumerable.Empty <TResult>());
                }
                var spView = new SpView();
                if (!string.IsNullOrEmpty(SpQueryArgs.Query))
                {
                    var q = new Caml.Query(SpQueryArgs.Query);
                    spView.Query.Where   = q.Where;
                    spView.Query.OrderBy = q.OrderBy;
                    spView.Query.GroupBy = q.GroupBy;
                }

                SpView = spView;
                var queryVisitor = new SpGeneratorQueryModelVisitor <TContext>(SpQueryArgs, spView);
                queryVisitor.VisitQueryModel(queryModel);

                if (spView.ViewFields == null)
                {
                    spView.ViewFields =
                        new ViewFieldsCamlElement(SpQueryArgs.FieldMappings.Select(fieldMapping => fieldMapping.Value.Name));
                }
                else if (!spView.ViewFields.Any())
                {
                    spView.ViewFields.AddRange(SpQueryArgs.FieldMappings.Select(fieldMapping => fieldMapping.Value.Name));
                }

                spView.Joins           = new JoinsCamlElement();
                spView.ProjectedFields = new ProjectedFieldsCamlElement();

                foreach (var dependentLookupField in SpQueryArgs.FieldMappings.Values.OfType <DependentLookupFieldAttribute>())
                {
                    if (spView.ViewFields.Any(f => f.Name == dependentLookupField.Name))
                    {
                        if (spView.ProjectedFields == null || !spView.ProjectedFields.Any(f => f.Name == dependentLookupField.Name))
                        {
                            spView.Joins.Join(new LeftJoin(dependentLookupField.LookupFieldName, dependentLookupField.List));
                            spView.ProjectedFields.ShowField(new CamlProjectedField(dependentLookupField.Name, dependentLookupField.List, dependentLookupField.ShowField));
                        }
                    }
                }

                if (SpQueryArgs.SkipResult)
                {
                    return(Enumerable.Empty <TResult>());
                }
                Debug.WriteLine($"# Entity: {typeof(TEntity)}");
                Debug.WriteLine($"# List: {this.SpQueryArgs}");
                Debug.WriteLine("# SP Query:");
                Debug.Write(spView);
                Debug.WriteLine("");

                IEnumerable <TResult> results = _manager.GetEntities(typeof(TResult), spView).Cast <TResult>();

                foreach (var resultOperator in queryModel.ResultOperators)
                {
                    if (resultOperator is ReverseResultOperator)
                    {
                        results = results.Reverse();
                    }
                }
                return(results);
            }
        }