Exemplo n.º 1
0
        private QueryValue BuildCollectionQueryValue(string propertyPath, QueryCollectionType queryCollectionType, EntitySetDataRow row)
        {
            QueryScalarType   scalarElementDataType      = queryCollectionType.ElementType as QueryScalarType;
            QueryComplexType  complexTypeElementDataType = queryCollectionType.ElementType as QueryComplexType;
            List <QueryValue> queryValues = new List <QueryValue>();

            if (scalarElementDataType != null)
            {
                int i = 0;
                while (row.PropertyPaths.Any(pp => pp == propertyPath + i))
                {
                    var value = row[propertyPath + i];
                    queryValues.Add(scalarElementDataType.CreateValue(value));
                    i++;
                }
            }
            else
            {
                ExceptionUtilities.CheckObjectNotNull(complexTypeElementDataType, "PropertyPath '{0}' is an invalid type '{1}'", propertyPath, queryCollectionType.ElementType);

                int i = 0;
                while (row.PropertyPaths.Where(pp => pp.StartsWith(propertyPath + i, StringComparison.Ordinal)).Count() > 0)
                {
                    QueryStructuralValue complexChildInstance = complexTypeElementDataType.CreateNewInstance();
                    this.BuildStructuralPropertiesQueryValue(complexChildInstance, propertyPath + i + ".", complexTypeElementDataType.ComplexType.Properties, complexTypeElementDataType.Properties, row);
                    queryValues.Add(complexChildInstance);
                    i++;
                }
            }

            return(queryCollectionType.CreateCollectionWithValues(queryValues.ToArray()));
        }
        /// <summary>
        /// Creates a QueryValue of a given type.
        /// </summary>
        /// <param name="type">Type of the QueryValue that will be generated.</param>
        /// <returns>QueryValue representing the provided object.</returns>
        public QueryValue Visit(QueryCollectionType type)
        {
            var resultFragment           = this.ResultFragmentStack.Pop();
            var resultCollectionElements = new List <QueryValue>();

            // need to materialize results first to get the complete graph, before we start converting to QueryValue
            var resultFragmentList = ((IEnumerable)resultFragment).Cast <object>().ToList();

            foreach (var resultFragmentElement in resultFragmentList)
            {
                var resultCollectionElement = this.Convert(resultFragmentElement, type.ElementType);
                resultCollectionElements.Add(resultCollectionElement);
            }

            return(type.CreateCollectionWithValues(resultCollectionElements));
        }