public void IsSpatialType_returns_true_for_all_spatial_types_only()
        {
            var spatialTypes =
                new[]
                    {
                        PrimitiveTypeKind.Geography,
                        PrimitiveTypeKind.Geometry,
                        PrimitiveTypeKind.GeometryPoint,
                        PrimitiveTypeKind.GeometryLineString,
                        PrimitiveTypeKind.GeometryPolygon,
                        PrimitiveTypeKind.GeometryMultiPoint,
                        PrimitiveTypeKind.GeometryMultiLineString,
                        PrimitiveTypeKind.GeometryMultiPolygon,
                        PrimitiveTypeKind.GeometryCollection,
                        PrimitiveTypeKind.GeographyPoint,
                        PrimitiveTypeKind.GeographyLineString,
                        PrimitiveTypeKind.GeographyPolygon,
                        PrimitiveTypeKind.GeographyMultiPoint,
                        PrimitiveTypeKind.GeographyMultiLineString,
                        PrimitiveTypeKind.GeographyMultiPolygon,
                        PrimitiveTypeKind.GeographyCollection,
                    };

            foreach (var value in Enum.GetValues(typeof(PrimitiveTypeKind)).OfType<PrimitiveTypeKind>())
            {
                var mockType = new Mock<PrimitiveType>();
                mockType.Setup(m => m.PrimitiveTypeKind).Returns(value);

                Assert.Equal(spatialTypes.Contains(value), mockType.Object.IsSpatialType());
            }
        }
 /// <summary>
 /// Is this a structured type? 
 /// Note: Structured, in this context means structured outside the server. 
 /// UDTs for instance, are considered to be scalar types - all WinFS types,
 /// would by this argument, be scalar types.
 /// </summary>
 /// <param name="type">The type to check</param>
 /// <returns>true, if the type is a structured type</returns>
 internal static bool IsStructuredType(md.TypeUsage type)
 {
     return (md.TypeSemantics.IsReferenceType(type) ||
             md.TypeSemantics.IsRowType(type) ||
             md.TypeSemantics.IsEntityType(type) ||
             md.TypeSemantics.IsRelationshipType(type) ||
             (md.TypeSemantics.IsComplexType(type)));
 }
        /// <summary>
        ///     Is there a parent child relationship between table1 and table2 ?
        /// </summary>
        /// <param name="table1"> parent table ? </param>
        /// <param name="table2"> child table ? </param>
        /// <param name="constraints"> list of constraints ? </param>
        /// <returns> true if there is at least one constraint </returns>
        internal bool IsParentChildRelationship(
            md.EntitySetBase table1, md.EntitySetBase table2,
            out List<ForeignKeyConstraint> constraints)
        {
            LoadRelationships(table1.EntityContainer);
            LoadRelationships(table2.EntityContainer);

            var extentPair = new ExtentPair(table1, table2);
            return m_parentChildRelationships.TryGetValue(extentPair, out constraints);
        }
        private readonly RootTypeInfo m_rootType; // the top-most type in this types type hierarchy

        #endregion

        #region Constructors and factory methods

        /// <summary>
        ///     Creates type information for a type
        /// </summary>
        /// <param name="type"> </param>
        /// <param name="superTypeInfo"> </param>
        /// <returns> </returns>
        internal static TypeInfo Create(md.TypeUsage type, TypeInfo superTypeInfo, ExplicitDiscriminatorMap discriminatorMap)
        {
            TypeInfo result;
            if (superTypeInfo == null)
            {
                result = new RootTypeInfo(type, discriminatorMap);
            }
            else
            {
                result = new TypeInfo(type, superTypeInfo);
            }
            return result;
        }
 protected TypeInfo(md.TypeUsage type, TypeInfo superType)
 {
     m_type = type;
     m_immediateSubTypes = new List<TypeInfo>();
     m_superType = superType;
     if (superType != null)
     {
         // Add myself to my supertype's list of subtypes
         superType.m_immediateSubTypes.Add(this);
         // my supertype's root type is mine as well
         m_rootType = superType.RootType;
     }
 }
        /// <summary>
        ///     Load all relationships in this entity container
        /// </summary>
        internal void LoadRelationships(md.EntityContainer entityContainer)
        {
            // Check to see if I've already loaded information for this entity container
            if (m_entityContainerMap.ContainsKey(entityContainer))
            {
                return;
            }

            // Load all relationships from this entitycontainer
            foreach (var e in entityContainer.BaseEntitySets)
            {
                var relationshipSet = e as md.RelationshipSet;
                if (relationshipSet == null)
                {
                    continue;
                }

                // Relationship sets can only contain relationships
                var relationshipType = relationshipSet.ElementType;
                var assocType = relationshipType as md.AssociationType;

                //
                // Handle only binary Association relationships for now
                //
                if (null == assocType
                    || !IsBinary(relationshipType))
                {
                    continue;
                }

                foreach (var constraint in assocType.ReferentialConstraints)
                {
                    List<ForeignKeyConstraint> fkConstraintList;
                    var fkConstraint = new ForeignKeyConstraint(relationshipSet, constraint);
                    if (!m_parentChildRelationships.TryGetValue(fkConstraint.Pair, out fkConstraintList))
                    {
                        fkConstraintList = new List<ForeignKeyConstraint>();
                        m_parentChildRelationships[fkConstraint.Pair] = fkConstraintList;
                    }
                    //
                    // Theoretically, we can have more than one fk constraint between
                    // the 2 tables (though, it is unlikely)
                    //
                    fkConstraintList.Add(fkConstraint);
                }
            }

            // Mark this entity container as already loaded
            m_entityContainerMap[entityContainer] = entityContainer;
        }
        public void Can_retrieve_properties()
        {
            var entityType = new EntityType("ET", "N", DataSpace.CSpace);
            var entitySet = new EntitySet("ES", "S", "T", "Q", entityType);
            var entityContainer = new EntityContainer("EC", DataSpace.SSpace);

            entityContainer.AddEntitySetBase(entitySet);

            var function = new EdmFunction("F", "N", DataSpace.SSpace, new EdmFunctionPayload());
            var parameterBindings
                = new[]
                  {
                      new ModificationFunctionParameterBinding(
                          new FunctionParameter(), 
                          new ModificationFunctionMemberPath(Enumerable.Empty<EdmMember>(), null),
                          true)
                  };
            var rowsAffectedParameter = new FunctionParameter("rows_affected", new TypeUsage(), ParameterMode.Out);

            var resultBindings
                = new[]
                  {
                      new ModificationFunctionResultBinding(
                          "C", 
                          EdmProperty.CreatePrimitive(
                              "P", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String)))
                  };

            var mapping
                = new ModificationFunctionMapping(
                    entitySet, entityType, function,
                    parameterBindings, rowsAffectedParameter, resultBindings);

            Assert.Same(rowsAffectedParameter, mapping.RowsAffectedParameter);
            Assert.Same(function, mapping.Function);
            Assert.Equal(parameterBindings, mapping.ParameterBindings);
            Assert.Equal(resultBindings, mapping.ResultBindings);
        }
        private static Dictionary<Var, md.EdmProperty> BuildOutputVarMap(PhysicalProjectOp projectOp, md.TypeUsage outputType)
        {
            var outputVarMap = new Dictionary<Var, md.EdmProperty>();

            PlanCompiler.Assert(md.TypeSemantics.IsRowType(outputType), "PhysicalProjectOp result type is not a RowType?");

            IEnumerator<md.EdmProperty> propertyEnumerator = TypeHelpers.GetEdmType<md.RowType>(outputType).Properties.GetEnumerator();
            IEnumerator<Var> varEnumerator = projectOp.Outputs.GetEnumerator();
            while (true)
            {
                var foundProp = propertyEnumerator.MoveNext();
                var foundVar = varEnumerator.MoveNext();
                if (foundProp != foundVar)
                {
                    throw EntityUtil.InternalError(EntityUtil.InternalErrorCode.ColumnCountMismatch, 1, null);
                }
                if (!foundProp)
                {
                    break;
                }
                outputVarMap[varEnumerator.Current] = propertyEnumerator.Current;
            }
            return outputVarMap;
        }
        /// <summary>
        ///     Build out an expression corresponding to the entitysetid
        /// </summary>
        /// <param name="entitySetidProperty"> the property corresponding to the entitysetid </param>
        /// <param name="op"> the *NewEntity op </param>
        /// <returns> </returns>
        private Node GetEntitySetIdExpr(md.EdmProperty entitySetIdProperty, NewEntityBaseOp op)
        {
            Node entitySetIdNode;
            var entitySet = op.EntitySet;
            if (entitySet != null)
            {
                var entitySetId = m_typeInfo.GetEntitySetId(entitySet);
                var entitySetIdOp = m_command.CreateInternalConstantOp(md.Helper.GetModelTypeUsage(entitySetIdProperty), entitySetId);
                entitySetIdNode = m_command.CreateNode(entitySetIdOp);
            }
            else
            {
                //
                // Not in a view context; simply assume a null entityset
                //
                entitySetIdNode = CreateNullConstantNode(md.Helper.GetModelTypeUsage(entitySetIdProperty));
            }

            return entitySetIdNode;
        }
        /// <summary>
        ///     Get the "new" type corresponding to the input type.
        ///     For structured types, we simply look up the typeInfoMap
        ///     For collection types, we create a new collection type based on the
        ///     "new" element type.
        ///     For enums we return the underlying type of the enum type.
        ///     For strong spatial types we return the union type that includes the strong spatial type.
        ///     For all other types, we simply return the input type
        /// </summary>
        /// <param name="type"> </param>
        /// <returns> </returns>
        private md.TypeUsage GetNewType(md.TypeUsage type)
        {
            md.TypeUsage newType;

            if (m_typeToNewTypeMap.TryGetValue(type, out newType))
            {
                return newType;
            }

            md.CollectionType collectionType;
            if (TypeHelpers.TryGetEdmType(type, out collectionType))
            {
                // If this is a collection type, then clone a new collection type
                var newElementType = GetNewType(collectionType.TypeUsage);
                newType = TypeUtils.CreateCollectionType(newElementType);
            }
            else if (TypeUtils.IsStructuredType(type))
            {
                // structured type => we've already calculated the input
                newType = m_typeInfo.GetTypeInfo(type).FlattenedTypeUsage;
            }
            else if (md.TypeSemantics.IsEnumerationType(type))
            {
                newType = TypeHelpers.CreateEnumUnderlyingTypeUsage(type);
            }
            else if (md.TypeSemantics.IsStrongSpatialType(type))
            {
                newType = TypeHelpers.CreateSpatialUnionTypeUsage(type);
            }
            else
            {
                // "simple" type => return the input type
                newType = type;
            }

            // Add this information to the map
            m_typeToNewTypeMap[type] = newType;
            return newType;
        }
        /// <summary>
        ///     This function builds a "property accessor" over the input expression.  It
        ///     can produce one of three results:
        ///     - It can return "null", if it is convinced that the input has no
        ///     such expression
        ///     - It can return a subnode of the input, if that subnode represents
        ///     the property
        ///     - Or, it can build a PropertyOp explicitly
        ///     Assertion: the property is not a structured type
        /// </summary>
        /// <param name="input"> The input expression </param>
        /// <param name="property"> The desired property </param>
        /// <returns> </returns>
        private Node BuildAccessor(Node input, md.EdmProperty property)
        {
            var inputOp = input.Op;

            // Special handling if the input is a NewRecordOp
            var newRecordOp = inputOp as NewRecordOp;
            if (null != newRecordOp)
            {
                int fieldPos;
                // Identify the specific property we're interested in.
                if (newRecordOp.GetFieldPosition(property, out fieldPos))
                {
                    return Copy(input.Children[fieldPos]);
                }
                else
                {
                    return null;
                }
            }

            // special handling if the input is a null
            if (inputOp.OpType
                == OpType.Null)
            {
                return null;
            }

            // The default case: Simply return a new PropertyOp
            var newPropertyOp = m_command.CreatePropertyOp(property);
            return m_command.CreateNode(newPropertyOp, Copy(input));
        }
        // <summary>
        // Tries to lookup custom discriminator map for the given type (applies to EntitySets with
        // TPH discrimination pattern)
        // </summary>
        private bool TryGetDiscriminatorMap(md.EdmType type, out ExplicitDiscriminatorMap discriminatorMap)
        {
            discriminatorMap = null;

            // check that there are actually discriminator maps available
            if (null == m_discriminatorMaps)
            {
                return false;
            }

            // must be an entity type...
            if (type.BuiltInTypeKind
                != md.BuiltInTypeKind.EntityType)
            {
                return false;
            }

            // get root entity type (discriminator maps are mapped from the root)
            var rootEntityType = GetRootType((md.EntityType)type);

            // find entity set
            md.EntitySet entitySet;
            if (!m_entityTypeToEntitySetMap.TryGetValue(rootEntityType, out entitySet))
            {
                return false;
            }

            // free floating entity constructors are stored with a null EntitySet
            if (entitySet == null)
            {
                return false;
            }

            // look for discriminator map
            return m_discriminatorMaps.TryGetValue(entitySet, out discriminatorMap);
        }
 private Node RewriteAsCastToUnderlyingType(md.PrimitiveType underlyingType, CastOp op, Node n)
 {
     // if type of the argument and the underlying type match we can strip the Cast entirely
     if (underlyingType.PrimitiveTypeKind
         == ((md.PrimitiveType)n.Child0.Op.Type.EdmType).PrimitiveTypeKind)
     {
         return n.Child0;
     }
     else
     {
         return m_command.CreateNode(m_command.CreateCastOp(md.TypeUsage.Create(underlyingType, op.Type.Facets)), n.Child0);
     }
 }
 /// <summary>
 ///     Returns a node for a null constant of the desired type
 /// </summary>
 /// <param name="type"> </param>
 /// <returns> </returns>
 private Node CreateNullConstantNode(md.TypeUsage type)
 {
     return m_command.CreateNode(m_command.CreateNullOp(type));
 }
        private void FlattenComputedVar(ComputedVar v, Node node, out List<Node> newNodes, out md.TypeUsage newType)
        {
            newNodes = new List<Node>();
            var definingExprNode = node.Child0; // defining expression for the VarDefOp
            newType = null;

            if (TypeUtils.IsCollectionType(v.Type))
            {
                PlanCompiler.Assert(definingExprNode.Op.OpType != OpType.Function, "Flattening of TVF output is not allowed.");
                newType = GetNewType(v.Type);
                Var newVar;
                var newVarDefNode = m_command.CreateVarDefNode(definingExprNode, out newVar);
                newNodes.Add(newVarDefNode);
                m_varInfoMap.CreateCollectionVarInfo(v, newVar);
                return;
            }

            // Get the "new" type for the Var
            var typeInfo = m_typeInfo.GetTypeInfo(v.Type);
            // Get a list of properties that we think are necessary 
            var desiredProperties = m_varPropertyMap[v];
            var newVars = new List<Var>();
            var newProps = new List<md.EdmProperty>();
            newNodes = new List<Node>();
            var hasNullSentinelVar = false;
            foreach (var p in typeInfo.PropertyRefList)
            {
                // do I care for this property?
                if (!desiredProperties.Contains(p))
                {
                    continue;
                }

                var newProperty = typeInfo.GetNewProperty(p);

                //
                // #479467 - Make sure that we build Vars for all properties - if
                // we are asked to produce all properties. This is extremely important
                // for the top-level Vars
                // 
                Node propAccessor = null;
                if (desiredProperties.AllProperties)
                {
                    propAccessor = BuildAccessorWithNulls(definingExprNode, newProperty);
                }
                else
                {
                    propAccessor = BuildAccessor(definingExprNode, newProperty);
                    if (propAccessor == null)
                    {
                        continue;
                    }
                }

                // Add the new property
                newProps.Add(newProperty);

                // Create a new VarDefOp. 
                Var newVar;
                var newVarDefNode = m_command.CreateVarDefNode(propAccessor, out newVar);
                newNodes.Add(newVarDefNode);
                newVars.Add(newVar);

                // Check if it is a null sentinel var
                if (!hasNullSentinelVar
                    && IsNullSentinelPropertyRef(p))
                {
                    hasNullSentinelVar = true;
                }
            }
            m_varInfoMap.CreateStructuredVarInfo(v, typeInfo.FlattenedType, newVars, newProps, hasNullSentinelVar);
            return;
        }
 internal TypeInfo GetTypeInfo(md.TypeUsage type)
 {
     if (!TypeUtils.IsStructuredType(type))
     {
         return null;
     }
     TypeInfo typeInfo = null;
     if (!m_typeInfoMap.TryGetValue(type, out typeInfo))
     {
         PlanCompiler.Assert(
             !TypeUtils.IsStructuredType(type) || !m_typeInfoMapPopulated,
             "cannot find typeInfo for type " + type);
     }
     return typeInfo;
 }
 /// <summary>
 ///     Try get the new property for the supplied propertyRef
 /// </summary>
 /// <param name="propertyRef"> property reference (on the old type) </param>
 /// <param name="throwIfMissing"> throw if the property is not found </param>
 /// <param name="newProperty"> the corresponding property on the new type </param>
 /// <returns> </returns>
 internal bool TryGetNewProperty(PropertyRef propertyRef, bool throwIfMissing, out md.EdmProperty newProperty)
 {
     return RootType.TryGetNewProperty(propertyRef, throwIfMissing, out newProperty);
 }
        // <summary>
        // Get the "new" type corresponding to the input type. For structured types,
        // we return the flattened record type.
        // For collections of structured type, we return a new collection type of the corresponding flattened
        // type.
        // For enum types we return the underlying type of the enum type.
        // For strong spatial types we return the union type that includes the strong spatial type.
        // For everything else, we return the input type
        // </summary>
        // <param name="type"> the original type </param>
        // <returns> the new type (if any) </returns>
        private md.TypeUsage GetNewType(md.TypeUsage type)
        {
            if (TypeUtils.IsStructuredType(type))
            {
                var typeInfo = GetTypeInfo(type);
                return typeInfo.FlattenedTypeUsage;
            }
            md.TypeUsage elementType;
            if (TypeHelpers.TryGetCollectionElementType(type, out elementType))
            {
                var newElementType = GetNewType(elementType);
                if (newElementType.EdmEquals(elementType))
                {
                    return type;
                }
                else
                {
                    return TypeHelpers.CreateCollectionTypeUsage(newElementType);
                }
            }

            if (TypeUtils.IsEnumerationType(type))
            {
                return TypeHelpers.CreateEnumUnderlyingTypeUsage(type);
            }

            if (md.TypeSemantics.IsStrongSpatialType(type))
            {
                return TypeHelpers.CreateSpatialUnionTypeUsage(type);
            }

            // simple scalar
            return type;
        }
 /// <summary>
 ///     Gets the list of "identity" properties for an entity. Gets the
 ///     "entitysetid" property in addition to the "key" properties
 /// </summary>
 /// <param name="type"> </param>
 /// <returns> </returns>
 private static PropertyRefList GetIdentityProperties(md.EntityType type)
 {
     var desiredProperties = GetKeyProperties(type);
     desiredProperties.Add(EntitySetIdPropertyRef.Instance);
     return desiredProperties;
 }
        // <summary>
        // "Explode" a type.  (ie) produce a flat record type with one property for each
        // scalar property (top-level or nested) of the original type.
        // Really deals with structured types, but also
        // peels off collection wrappers
        // </summary>
        // <param name="type"> the type to explode </param>
        // <returns> the typeinfo for this type (with the explosion) </returns>
        private TypeInfo ExplodeType(md.TypeUsage type)
        {
            if (TypeUtils.IsStructuredType(type))
            {
                var typeInfo = GetTypeInfo(type);
                ExplodeType(typeInfo);
                return typeInfo;
            }

            if (TypeUtils.IsCollectionType(type))
            {
                var elementType = TypeHelpers.GetEdmType<md.CollectionType>(type).TypeUsage;
                ExplodeType(elementType);
                return null;
            }
            return null;
        }
        private TypeInfo CreateTypeInfoForStructuredType(md.TypeUsage type, ExplicitDiscriminatorMap discriminatorMap)
        {
            TypeInfo typeInfo;

            PlanCompiler.Assert(TypeUtils.IsStructuredType(type), "expected structured type. Found " + type);

            // Return existing entry, if one is available
            typeInfo = GetTypeInfo(type);
            if (typeInfo != null)
            {
                return typeInfo;
            }

            // Ensure that my supertype has been added to the map. 
            TypeInfo superTypeInfo = null;
            md.RefType refType;
            if (type.EdmType.BaseType != null)
            {
                superTypeInfo = CreateTypeInfoForStructuredType(md.TypeUsage.Create(type.EdmType.BaseType), discriminatorMap);
            }
            // 
            // Handle Ref types also in a similar fashion
            //
            else if (TypeHelpers.TryGetEdmType(type, out refType))
            {
                var entityType = refType.ElementType as md.EntityType;
                if (entityType != null
                    && entityType.BaseType != null)
                {
                    var baseRefType = TypeHelpers.CreateReferenceTypeUsage(entityType.BaseType as md.EntityType);
                    superTypeInfo = CreateTypeInfoForStructuredType(baseRefType, discriminatorMap);
                }
            }

            //
            // Add the types of my properties to the TypeInfo map
            // 
            foreach (md.EdmMember m in TypeHelpers.GetDeclaredStructuralMembers(type))
            {
                CreateTypeInfoForType(m.TypeUsage);
            }

            // 
            // Get the types of the rel properties also
            //
            {
                md.EntityTypeBase entityType;
                if (TypeHelpers.TryGetEdmType(type, out entityType))
                {
                    foreach (var p in m_relPropertyHelper.GetDeclaredOnlyRelProperties(entityType))
                    {
                        CreateTypeInfoForType(p.ToEnd.TypeUsage);
                    }
                }
            }

            // Now add myself to the map
            typeInfo = TypeInfo.Create(type, superTypeInfo, discriminatorMap);
            m_typeInfoMap.Add(type, typeInfo);

            return typeInfo;
        }
        // <summary>
        // Create a TypeInfo (if necessary) for the type, and add it to the TypeInfo map
        // </summary>
        // <param name="type"> the type to process </param>
        private void CreateTypeInfoForType(md.TypeUsage type)
        {
            //
            // peel off all collection wrappers
            //
            while (TypeUtils.IsCollectionType(type))
            {
                type = TypeHelpers.GetEdmType<md.CollectionType>(type).TypeUsage;
            }

            // Only add "structured" types
            if (TypeUtils.IsStructuredType(type))
            {
                // check for discriminator map...
                ExplicitDiscriminatorMap discriminatorMap;
                TryGetDiscriminatorMap(type.EdmType, out discriminatorMap);

                CreateTypeInfoForStructuredType(type, discriminatorMap);
            }
        }
 /// <summary>
 ///     A BuildAccessor variant. If the appropriate property was not found, then
 ///     build up a null constant instead
 /// </summary>
 /// <param name="input"> </param>
 /// <param name="property"> </param>
 /// <returns> </returns>
 private Node BuildAccessorWithNulls(Node input, md.EdmProperty property)
 {
     var newNode = BuildAccessor(input, property);
     if (newNode == null)
     {
         newNode = CreateNullConstantNode(md.Helper.GetModelTypeUsage(property));
     }
     return newNode;
 }
        internal int GetEntitySetId(md.EntitySet e)
        {
            var result = 0;

            if (!m_entitySetToEntitySetIdMap.TryGetValue(e, out result))
            {
                PlanCompiler.Assert(false, "no such entity set?");
            }
            return result;
        }
 private Node BuildSoftCast(Node node, md.TypeUsage targetType)
 {
     PlanCompiler.Assert(node.Op.IsScalarOp, "Attempting SoftCast around non-ScalarOp?");
     if (Command.EqualTypes(node.Op.Type, targetType))
     {
         return node;
     }
     // Skip any castOps we may have created already
     while (node.Op.OpType
            == OpType.SoftCast)
     {
         node = node.Child0;
     }
     var newNode = m_command.CreateNode(m_command.CreateSoftCastOp(targetType), node);
     return newNode;
 }
 // <summary>
 // Gets the "single" entityset that stores instances of this type
 // </summary>
 internal md.EntitySet GetEntitySet(md.EntityTypeBase type)
 {
     md.EntitySet set;
     var rootType = GetRootType(type);
     if (!m_entityTypeToEntitySetMap.TryGetValue(rootType, out set))
     {
         return null;
     }
     return set;
 }
        /// <summary>
        ///     Build up a key-value pair of (property, expression) to represent
        ///     the extraction of the appropriate property from the input expression
        /// </summary>
        /// <param name="input"> The input (structured type) expression </param>
        /// <param name="property"> The property in question </param>
        /// <param name="ignoreMissingProperties"> should we ignore missing properties </param>
        /// <returns> </returns>
        private KeyValuePair<md.EdmProperty, Node> GetPropertyValue(Node input, md.EdmProperty property, bool ignoreMissingProperties)
        {
            Node n = null;

            if (!ignoreMissingProperties)
            {
                n = BuildAccessorWithNulls(input, property);
            }
            else
            {
                n = BuildAccessor(input, property);
            }
            return new KeyValuePair<md.EdmProperty, Node>(property, n);
        }
 private IEnumerable<md.EdmProperty> GetTvfResultKeys(md.EdmFunction tvf)
 {
     md.EdmProperty[] keys;
     if (m_tvfResultKeys.TryGetValue(tvf, out keys))
     {
         return keys;
     }
     return Enumerable.Empty<md.EdmProperty>();
 }
 private static PropertyRefList GetKeyProperties(md.EntityType entityType)
 {
     var desiredProperties = new PropertyRefList();
     foreach (var p in entityType.KeyMembers)
     {
         var edmP = p as md.EdmProperty;
         PlanCompiler.Assert(edmP != null, "EntityType had non-EdmProperty key member?");
         var pRef = new SimplePropertyRef(edmP);
         desiredProperties.Add(pRef);
     }
     return desiredProperties;
 }
        // <summary>
        // Add a new entry to the entityTypeToSet map
        // </summary>
        // <param name="entityType"> entity type </param>
        // <param name="entitySet"> entityset producing this type </param>
        private void AddEntityTypeToSetEntry(md.EntityType entityType, md.EntitySet entitySet)
        {
            md.EntitySet other;
            var rootType = GetRootType(entityType);
            var hasSingleEntitySet = true;

            if (entitySet == null)
            {
                hasSingleEntitySet = false;
            }
            else if (m_entityTypeToEntitySetMap.TryGetValue(rootType, out other))
            {
                if (other != entitySet)
                {
                    hasSingleEntitySet = false;
                }
            }

            if (hasSingleEntitySet)
            {
                m_entityTypeToEntitySetMap[rootType] = entitySet;
            }
            else
            {
                m_entityTypeToEntitySetMap[rootType] = null;
            }
        }