コード例 #1
0
        protected Dictionary <ExpandNode, TempTableNode> CreateChildren(IEnumerable <ExpandNode> qChildren, TempTableNode node,
                                                                        out IEnumerable <string> relatedPropertiesForSelect)
        {
            Dictionary <ExpandNode, TempTableNode> childDict = new Dictionary <ExpandNode, TempTableNode>();

            List <string> childrenForSelect = new List <string>();

            foreach (ExpandNode qChild in qChildren)
            {
                TempTableNode child;
                string[]      select = new string[qChild.Query.Select.Properties.Length];
                qChild.Query.Select.Properties.CopyTo(select, 0);
                if (qChild is EntityExpandNode)
                {
                    child = new EntityTempNode(qChild.Property, select, qChild.Entity);
                }
                else if (qChild is CollectionExpandNode)
                {
                    Order[] orderby = GetOrders(qChild.Query);
                    child = new CollectionTempNode(qChild.Property, select, orderby, qChild.Entity);
                }
                else
                {
                    throw new NotSupportedException(qChild.GetType().ToString()); // never
                }
                child.Path = node.Path + "/" + qChild.Property;

                //
                DirectRelationship          firstDirectRelationship = qChild.Relationship.DirectRelationships[0];
                Dictionary <string, string> relatedKey = new Dictionary <string, string>();
                for (int i = 0; i < firstDirectRelationship.Properties.Length; i++)
                {
                    relatedKey.Add(firstDirectRelationship.Properties[i], firstDirectRelationship.RelatedProperties[i]);
                }
                child.RelatedKey = relatedKey;

                node.Children.Add(child);

                // NativeProperties
                childrenForSelect.AddRange(firstDirectRelationship.Properties);

                childDict.Add(qChild, child);
            }

            relatedPropertiesForSelect = childrenForSelect.Distinct();

            return(childDict);
        }
コード例 #2
0
        protected TempTableNode BuildTempTableTree(QueryExpand queryExpand)
        {
            Query query = queryExpand.Query;

            XElement entitySchema = query.Schema.GetEntitySchema(query.Entity);
            string   name         = entitySchema.Attribute(SchemaVocab.Collection).Value;

            string[] select = new string[query.Select.Properties.Length];
            query.Select.Properties.CopyTo(select, 0);
            Order[]       orderby = GetOrders(query);
            TempTableNode root    = new CollectionTempNode(name, select, orderby, query.Entity)
            {
                Path = name
            };

            //
            Dictionary <ExpandNode, TempTableNode> childrenDict = CreateChildren(queryExpand.Nodes, root, out IEnumerable <string> relatedPropertiesForSelect);

            query.Select.Properties = query.Select.Properties.Union(relatedPropertiesForSelect).ToArray();
            query.Properties.UnionFieldProperties(relatedPropertiesForSelect);

            //
            if (query.Top != 0 || query.Skip != 0)
            {
                SetRootPagingStatments(root, queryExpand);
            }
            else
            {
                SetRootSelectStatments(root, queryExpand);
            }

            //
            foreach (KeyValuePair <ExpandNode, TempTableNode> pair in childrenDict)
            {
                pair.Value.ParentTempTableName = root.TempTableName;
                Compose(pair.Key, pair.Value);
            }

            return(root);
        }