protected override IEnumerable <EntitySetHandle> OnVisitItems(EvaluationContext evalContext)
        {
            // The relationship (definition) being accessed
            // (don't evaluate in loop for now ... OK while they're just literals)
            IEntity relationship = Right.EvaluateEntity(evalContext);

            IEntity current = Left.EvaluateEntity(evalContext);

            if (current == null)
            {
                yield break;
            }

            // Relationship data
            IEntityRelationshipCollection <IEntity> values = current.GetRelationships(relationship,
                                                                                      Direction);

            foreach (var pair in values)
            {
                var result = new EntitySetHandle
                {
                    Entity     = pair != null ? pair.Entity : null,
                    Expression = this
                };
                yield return(result);
            }
        }
Пример #2
0
 public void AddParent(EntitySetHandle parent)
 {
     if (Parents == null)
     {
         Parents = new List <EntitySetHandle>();
     }
     Parents.Add(parent);
 }
Пример #3
0
        protected override IEnumerable <EntitySetHandle> OnVisitItems(EvaluationContext evalContext)
        {
            EntitySetHandle handle = new EntitySetHandle
            {
                Expression = this
            };

            yield return(handle);
        }
Пример #4
0
        protected override IEnumerable <EntitySetHandle> OnVisitItems(EvaluationContext evalContext)
        {
            var result = new EntitySetHandle
            {
                Entity     = evalContext.Settings.ContextEntity,
                Expression = this
            };

            yield return(result);
        }
Пример #5
0
        protected override IEnumerable <EntitySetHandle> OnVisitItems(EvaluationContext evalContext)
        {
            // The instances passed in via the parameter
            IEnumerable <IEntity> instances = GetParameterList(evalContext);

            foreach (var instance in instances)
            {
                var result = new EntitySetHandle
                {
                    Entity     = instance,
                    Expression = this
                };
                yield return(result);
            }
        }
Пример #6
0
        protected virtual IEnumerable <EntitySetHandle> OnVisitAllItems(EvaluationContext evalContext)
        {
            // Yes .. this is a hack
            // The problem is its not necessarily the case that children should or should not constrain the parent
            // The problem is that the tree itself is built wrong.. the root node should be the 'where' node if the overall result set is to be filtered.
            bool childrenWillContrainParent = ChildContainer.ChildEntityNodes.Any(node => node is WhereNode);

            // Return handle to Visit each entity
            IEnumerable <EntitySetHandle> handles = OnVisitItems(evalContext).Select(handle => { handle.Activate(evalContext); return(handle); });

            // (Wraps are used to track if any of the joins were non-default-nulls)
            var handleWraps = handles.Select(h => new HandleWrap {
                Handle = h, IsNotEmpty = !childrenWillContrainParent
            });

            // And cross-join all child nodes against each other.
            // Note: these are effectively left-joined to the parent. (We use the DefaultIfEmpty to ensure that each set returns at least one value, to ensure they act as a left join).
            var handlesEx = ChildContainer.ChildEntityNodes.Aggregate
                            (
                seed: handleWraps,
                func: (accumHandles, joinNode) => accumHandles.SelectMany(
                    collectionSelector: handle => AddDefaultRowIfRequired(joinNode.VisitItems(evalContext), evalContext),
                    resultSelector: (parent, child) =>
            {
                bool wasEmpty = child == null;
                if (wasEmpty)
                {
                    child = new EntitySetHandle {
                        Expression = joinNode
                    }
                }
                ;
                child.AddParent(parent.Handle);
                return(new HandleWrap {
                    Handle = child, IsNotEmpty = !wasEmpty
                });
            }
                    )
                            );

            if (childrenWillContrainParent)
            {
                handlesEx = handlesEx.Where(hw => hw.IsNotEmpty);
            }

            return(handlesEx.Select(hw => hw.Handle));
        }
Пример #7
0
        protected override IEnumerable <EntitySetHandle> OnVisitItems(EvaluationContext evalContext)
        {
            IEntity instance = Instance.Entity;

            if (instance == null)
            {
                yield break;
            }

            var result = new EntitySetHandle
            {
                Entity     = instance,
                Expression = this
            };

            yield return(result);
        }
Пример #8
0
        protected override IEnumerable <EntitySetHandle> OnVisitItems(EvaluationContext evalContext)
        {
            // The type of instances to load
            IEntity type = Argument.EvaluateEntity(evalContext);

            // Get instances
            IEnumerable <IEntity> instances = Entity.GetInstancesOfType(new EntityRef(type.Id), true);

            foreach (var instance in instances)
            {
                var result = new EntitySetHandle
                {
                    Entity     = instance,
                    Expression = this
                };
                yield return(result);
            }
        }