Example #1
0
        internal override void Validate()
        {
            if (this._isAlreadyValidated)
            {
                return;
            }
            base.Validate();
            if (this.ExtendingEntityContainer != null)
            {
                this.ExtendingEntityContainer.Validate();
                foreach (SchemaElement member in this.ExtendingEntityContainer.Members)
                {
                    AddErrorKind error = this.Members.TryAdd(member.Clone((SchemaElement)this));
                    this.DuplicateOrEquivalentMemberNameWhileExtendingEntityContainer(member, error);
                }
            }
            HashSet <string> tableKeys = new HashSet <string>();

            foreach (SchemaElement member in this.Members)
            {
                EntityContainerEntitySet entitySet = member as EntityContainerEntitySet;
                if (entitySet != null && this.Schema.DataModel == SchemaDataModelOption.ProviderDataModel)
                {
                    this.CheckForDuplicateTableMapping(tableKeys, entitySet);
                }
                member.Validate();
            }
            this.ValidateRelationshipSetHaveUniqueEnds();
            this.ValidateOnlyBaseEntitySetTypeDefinesConcurrency();
            this._isAlreadyValidated = true;
        }
Example #2
0
        private IRelationshipEnd InferRelationshipEnd(EntityContainerEntitySet set)
        {
            if (this.ParentElement.Relationship == null)
            {
                return((IRelationshipEnd)null);
            }
            List <IRelationshipEnd> relationshipEndList = new List <IRelationshipEnd>();

            foreach (IRelationshipEnd end in (IEnumerable <IRelationshipEnd>) this.ParentElement.Relationship.Ends)
            {
                if (set.EntityType.IsOfType((StructuredType)end.Type))
                {
                    relationshipEndList.Add(end);
                }
            }
            if (relationshipEndList.Count == 1)
            {
                return(relationshipEndList[0]);
            }
            if (relationshipEndList.Count == 0)
            {
                this.AddError(ErrorCode.FailedInference, EdmSchemaErrorSeverity.Error, (object)Strings.InferRelationshipEndFailedNoEntitySetMatch((object)set.Name, (object)this.ParentElement.Name, (object)this.ParentElement.Relationship.FQName, (object)set.EntityType.FQName, (object)this.ParentElement.ParentElement.FQName));
            }
            else
            {
                this.AddError(ErrorCode.FailedInference, EdmSchemaErrorSeverity.Error, (object)Strings.InferRelationshipEndAmbiguous((object)set.Name, (object)this.ParentElement.Name, (object)this.ParentElement.Relationship.FQName, (object)set.EntityType.FQName, (object)this.ParentElement.ParentElement.FQName));
            }
            return((IRelationshipEnd)null);
        }
Example #3
0
        private void HandleEntitySetElement(XmlReader reader)
        {
            EntityContainerEntitySet containerEntitySet = new EntityContainerEntitySet(this);

            containerEntitySet.Parse(reader);
            this.Members.Add((SchemaElement)containerEntitySet, true, new Func <object, string>(Strings.DuplicateEntityContainerMemberName));
        }
Example #4
0
        private void HandleEntitySetElement(XmlReader reader)
        {
            DebugCheck.NotNull(reader);
            var set = new EntityContainerEntitySet(this);

            set.Parse(reader);
            Members.Add(set, true, Strings.DuplicateEntityContainerMemberName);
        }
Example #5
0
        internal override SchemaElement Clone(SchemaElement parentElement)
        {
            EntityContainerEntitySet containerEntitySet = new EntityContainerEntitySet((EntityContainer)parentElement);

            containerEntitySet._definingQueryElement = this._definingQueryElement;
            containerEntitySet._entityType           = this._entityType;
            containerEntitySet._schema = this._schema;
            containerEntitySet._table  = this._table;
            containerEntitySet.Name    = this.Name;
            return((SchemaElement)containerEntitySet);
        }
Example #6
0
        /// <summary>
        ///     Adds a child EntitySet's tableKey (Schema/Table combination) to the validation collection
        ///     This is used to validate that no child EntitySets share a Schema.Table combination
        /// </summary>
        private void CheckForDuplicateTableMapping(HashSet <string> tableKeys, EntityContainerEntitySet entitySet)
        {
            string schema;
            string table;

            if (String.IsNullOrEmpty(entitySet.DbSchema))
            {
                // if there is no specified DbSchema, use the parent EntityContainer's name
                schema = Name;
            }
            else
            {
                schema = entitySet.DbSchema;
            }

            if (String.IsNullOrEmpty(entitySet.Table))
            {
                // if there is no specified Table, use the EntitySet's name
                table = entitySet.Name;
            }
            else
            {
                table = entitySet.Table;
            }

            // create a key using the DbSchema and Table
            var tableKey = String.Format(CultureInfo.InvariantCulture, "{0}.{1}", schema, table);

            if (entitySet.DefiningQuery != null)
            {
                // don't consider the schema name for defining queries, because
                // we can't say for sure that it is the same as the entity container
                // so in this example
                //
                // <EntityContainer Name="dbo">
                //   <EntitySet Name="ByVal">
                //     <DefiningQuery>Select col1 from dbi.ByVal</DefiningQuery>
                //   </EntitySet>
                //   <EntitySet Name="ByVal1" Table="ByVal"/>
                //   ...
                //
                // ByVal and ByVal1 should not conflict in our check
                tableKey = entitySet.Name;
            }

            var alreadyExisted = !tableKeys.Add(tableKey);

            if (alreadyExisted)
            {
                entitySet.AddError(
                    ErrorCode.AlreadyDefined, EdmSchemaErrorSeverity.Error, Strings.DuplicateEntitySetTable(entitySet.Name, schema, table));
            }
        }
        internal override SchemaElement Clone(SchemaElement parentElement)
        {
            var entitySet = new EntityContainerEntitySet((EntityContainer)parentElement);

            entitySet._definingQueryElement = _definingQueryElement;
            entitySet._entityType           = _entityType;
            entitySet._schema = _schema;
            entitySet._table  = _table;
            entitySet.Name    = Name;

            return(entitySet);
        }
Example #8
0
 private void ValidateFunctionImportReturnType(
     SchemaElement owner,
     SchemaType returnType,
     CollectionKind returnTypeCollectionKind,
     EntityContainerEntitySet entitySet,
     bool entitySetPathDefined)
 {
     if (returnType != null && !this.ReturnTypeMeetsFunctionImportBasicRequirements(returnType, returnTypeCollectionKind))
     {
         owner.AddError(ErrorCode.FunctionImportUnsupportedReturnType, EdmSchemaErrorSeverity.Error, owner, (object)this.GetReturnTypeErrorMessage(this.Name));
     }
     this.ValidateFunctionImportReturnType(owner, returnType, entitySet, entitySetPathDefined);
 }
Example #9
0
 private void InferEnds()
 {
     foreach (IRelationshipEnd end in (IEnumerable <IRelationshipEnd>) this.Relationship.Ends)
     {
         if (!this.HasEnd(end.Name))
         {
             EntityContainerEntitySet entitySet = this.InferEntitySet(end);
             if (entitySet != null)
             {
                 this.AddEnd(end, entitySet);
             }
         }
     }
 }
Example #10
0
 internal override void ResolveTopLevelNames()
 {
     base.ResolveTopLevelNames();
     if (this._entitySet != null)
     {
         return;
     }
     this._entitySet = this.ParentElement.ParentElement.FindEntitySet(this._unresolvedEntitySetName);
     if (this._entitySet != null)
     {
         return;
     }
     this.AddError(ErrorCode.InvalidEndEntitySet, EdmSchemaErrorSeverity.Error, (object)Strings.InvalidEntitySetNameReference((object)this._unresolvedEntitySetName, (object)this.Name));
 }
Example #11
0
        protected override void AddEnd(
            IRelationshipEnd relationshipEnd,
            EntityContainerEntitySet entitySet)
        {
            EntityContainerAssociationSetEnd associationSetEnd = new EntityContainerAssociationSetEnd(this);

            associationSetEnd.Role            = relationshipEnd.Name;
            associationSetEnd.RelationshipEnd = relationshipEnd;
            associationSetEnd.EntitySet       = entitySet;
            if (associationSetEnd.EntitySet == null)
            {
                return;
            }
            this._relationshipEnds.Add(associationSetEnd.Role, associationSetEnd);
        }
        // <summary>
        // Used during the resolve phase to resolve the type name to the object that represents that type
        // </summary>
        internal override void ResolveTopLevelNames()
        {
            base.ResolveTopLevelNames();

            if (_entitySet == null)
            {
                _entitySet = ParentElement.ParentElement.FindEntitySet(_unresolvedEntitySetName);
                if (_entitySet == null)
                {
                    AddError(
                        ErrorCode.InvalidEndEntitySet, EdmSchemaErrorSeverity.Error,
                        Strings.InvalidEntitySetNameReference(_unresolvedEntitySetName, Name));
                }
            }
        }
Example #13
0
        private void ValidateFunctionImportReturnType(
            SchemaElement owner,
            SchemaType returnType,
            EntityContainerEntitySet entitySet,
            bool entitySetPathDefined)
        {
            SchemaEntityType schemaEntityType = returnType as SchemaEntityType;

            if (entitySet != null && entitySetPathDefined)
            {
                owner.AddError(ErrorCode.FunctionImportEntitySetAndEntitySetPathDeclared, EdmSchemaErrorSeverity.Error, (object)Strings.FunctionImportEntitySetAndEntitySetPathDeclared((object)this.FQName));
            }
            if (schemaEntityType != null)
            {
                if (entitySet == null)
                {
                    owner.AddError(ErrorCode.FunctionImportReturnsEntitiesButDoesNotSpecifyEntitySet, EdmSchemaErrorSeverity.Error, (object)Strings.FunctionImportReturnEntitiesButDoesNotSpecifyEntitySet((object)this.FQName));
                }
                else
                {
                    if (entitySet.EntityType == null || schemaEntityType.IsOfType((StructuredType)entitySet.EntityType))
                    {
                        return;
                    }
                    owner.AddError(ErrorCode.FunctionImportEntityTypeDoesNotMatchEntitySet, EdmSchemaErrorSeverity.Error, (object)Strings.FunctionImportEntityTypeDoesNotMatchEntitySet((object)this.FQName, (object)entitySet.EntityType.FQName, (object)entitySet.Name));
                }
            }
            else
            {
                SchemaComplexType schemaComplexType = returnType as SchemaComplexType;
                if (schemaComplexType != null)
                {
                    if (entitySet == null && !entitySetPathDefined)
                    {
                        return;
                    }
                    owner.AddError(ErrorCode.ComplexTypeAsReturnTypeAndDefinedEntitySet, EdmSchemaErrorSeverity.Error, owner.LineNumber, owner.LinePosition, (object)Strings.ComplexTypeAsReturnTypeAndDefinedEntitySet((object)this.FQName, (object)schemaComplexType.Name));
                }
                else
                {
                    if (entitySet == null && !entitySetPathDefined)
                    {
                        return;
                    }
                    owner.AddError(ErrorCode.FunctionImportSpecifiesEntitySetButDoesNotReturnEntityType, EdmSchemaErrorSeverity.Error, (object)Strings.FunctionImportSpecifiesEntitySetButNotEntityType((object)this.FQName));
                }
            }
        }
Example #14
0
 internal void ResolveEntitySet(
     SchemaElement owner,
     string unresolvedEntitySet,
     ref EntityContainerEntitySet entitySet)
 {
     if (entitySet != null || unresolvedEntitySet == null)
     {
         return;
     }
     entitySet = this._container.FindEntitySet(unresolvedEntitySet);
     if (entitySet != null)
     {
         return;
     }
     owner.AddError(ErrorCode.FunctionImportUnknownEntitySet, EdmSchemaErrorSeverity.Error, (object)Strings.FunctionImportUnknownEntitySet((object)unresolvedEntitySet, (object)this.FQName));
 }
Example #15
0
        // <summary>
        // Create and add a EntityContainerEnd from the IRelationshipEnd provided
        // </summary>
        // <param name="relationshipEnd"> The relationship end of the end to add. </param>
        // <param name="entitySet"> The entitySet to associate with the relationship end. </param>
        protected override void AddEnd(IRelationshipEnd relationshipEnd, EntityContainerEntitySet entitySet)
        {
            DebugCheck.NotNull(relationshipEnd);
            Debug.Assert(!_relationshipEnds.ContainsKey(relationshipEnd.Name));
            // we expect set to be null sometimes

            var end = new EntityContainerAssociationSetEnd(this);

            end.Role            = relationshipEnd.Name;
            end.RelationshipEnd = relationshipEnd;

            end.EntitySet = entitySet;
            if (end.EntitySet != null)
            {
                _relationshipEnds.Add(end.Role, end);
            }
        }
Example #16
0
        private void CheckForDuplicateTableMapping(
            HashSet <string> tableKeys,
            EntityContainerEntitySet entitySet)
        {
            string str1 = !string.IsNullOrEmpty(entitySet.DbSchema) ? entitySet.DbSchema : this.Name;
            string str2 = !string.IsNullOrEmpty(entitySet.Table) ? entitySet.Table : entitySet.Name;
            string str3 = string.Format((IFormatProvider)CultureInfo.InvariantCulture, "{0}.{1}", (object)str1, (object)str2);

            if (entitySet.DefiningQuery != null)
            {
                str3 = entitySet.Name;
            }
            if (tableKeys.Add(str3))
            {
                return;
            }
            entitySet.AddError(ErrorCode.AlreadyDefined, EdmSchemaErrorSeverity.Error, (object)Strings.DuplicateEntitySetTable((object)entitySet.Name, (object)str1, (object)str2));
        }
Example #17
0
        /// <summary>
        ///     If the role name is missing but an entity set is given, figure out what the
        ///     relationship end should be
        /// </summary>
        /// <param name="set"> The given EntitySet </param>
        /// <returns> The appropriate relationship end </returns>
        private IRelationshipEnd InferRelationshipEnd(EntityContainerEntitySet set)
        {
            DebugCheck.NotNull(set);

            if (ParentElement.Relationship == null)
            {
                return(null);
            }

            var possibleEnds = new List <IRelationshipEnd>();

            foreach (var end in ParentElement.Relationship.Ends)
            {
                if (set.EntityType.IsOfType(end.Type))
                {
                    possibleEnds.Add(end);
                }
            }

            if (possibleEnds.Count == 1)
            {
                return(possibleEnds[0]);
            }
            else if (possibleEnds.Count == 0)
            {
                // no matchs
                AddError(
                    ErrorCode.FailedInference, EdmSchemaErrorSeverity.Error,
                    Strings.InferRelationshipEndFailedNoEntitySetMatch(
                        set.Name, ParentElement.Name, ParentElement.Relationship.FQName, set.EntityType.FQName,
                        ParentElement.ParentElement.FQName));
            }
            else
            {
                // ambiguous
                AddError(
                    ErrorCode.FailedInference, EdmSchemaErrorSeverity.Error,
                    Strings.InferRelationshipEndAmbiguous(
                        set.Name, ParentElement.Name, ParentElement.Relationship.FQName, set.EntityType.FQName,
                        ParentElement.ParentElement.FQName));
            }

            return(null);
        }
Example #18
0
 private static bool TypeIsSubTypeOf(
     SchemaEntityType itemType,
     Dictionary <SchemaEntityType, EntityContainerEntitySet> baseEntitySetTypes,
     out EntityContainerEntitySet set)
 {
     if (itemType.IsTypeHierarchyRoot)
     {
         set = (EntityContainerEntitySet)null;
         return(false);
     }
     for (SchemaEntityType baseType = itemType.BaseType as SchemaEntityType; baseType != null; baseType = baseType.BaseType as SchemaEntityType)
     {
         if (baseEntitySetTypes.ContainsKey(baseType))
         {
             set = baseEntitySetTypes[baseType];
             return(true);
         }
     }
     set = (EntityContainerEntitySet)null;
     return(false);
 }
Example #19
0
        private void ValidateOnlyBaseEntitySetTypeDefinesConcurrency()
        {
            Dictionary <SchemaEntityType, EntityContainerEntitySet> baseEntitySetTypes = new Dictionary <SchemaEntityType, EntityContainerEntitySet>();

            foreach (SchemaElement member in this.Members)
            {
                EntityContainerEntitySet containerEntitySet = member as EntityContainerEntitySet;
                if (containerEntitySet != null && !baseEntitySetTypes.ContainsKey(containerEntitySet.EntityType))
                {
                    baseEntitySetTypes.Add(containerEntitySet.EntityType, containerEntitySet);
                }
            }
            foreach (SchemaType schemaType in this.Schema.SchemaTypes)
            {
                SchemaEntityType         itemType = schemaType as SchemaEntityType;
                EntityContainerEntitySet set;
                if (itemType != null && EntityContainer.TypeIsSubTypeOf(itemType, baseEntitySetTypes, out set) && EntityContainer.TypeDefinesNewConcurrencyProperties(itemType))
                {
                    this.AddError(ErrorCode.ConcurrencyRedefinedOnSubTypeOfEntitySetType, EdmSchemaErrorSeverity.Error, (object)Strings.ConcurrencyRedefinedOnSubTypeOfEntitySetType((object)itemType.FQName, (object)set.EntityType.FQName, (object)set.FQName));
                }
            }
        }
Example #20
0
        private static bool TypeIsSubTypeOf(
            SchemaEntityType itemType, Dictionary <SchemaEntityType, EntityContainerEntitySet> baseEntitySetTypes,
            out EntityContainerEntitySet set)
        {
            if (itemType.IsTypeHierarchyRoot)
            {
                // can't be a sub type if we are a base type
                set = null;
                return(false);
            }

            // walk up the hierarchy looking for a base that is the base type of an entityset
            for (var baseType = itemType.BaseType as SchemaEntityType; baseType != null; baseType = baseType.BaseType as SchemaEntityType)
            {
                if (baseEntitySetTypes.ContainsKey(baseType))
                {
                    set = baseEntitySetTypes[baseType];
                    return(true);
                }
            }

            set = null;
            return(false);
        }
        internal override SchemaElement Clone(SchemaElement parentElement)
        {
            var entitySet = new EntityContainerEntitySet((EntityContainer)parentElement);
            entitySet._definingQueryElement = _definingQueryElement;
            entitySet._entityType = _entityType;
            entitySet._schema = _schema;
            entitySet._table = _table;
            entitySet.Name = Name;

            return entitySet;
        }
        // <summary>
        // If the role name is missing but an entity set is given, figure out what the
        // relationship end should be
        // </summary>
        // <param name="set"> The given EntitySet </param>
        // <returns> The appropriate relationship end </returns>
        private IRelationshipEnd InferRelationshipEnd(EntityContainerEntitySet set)
        {
            DebugCheck.NotNull(set);

            if (ParentElement.Relationship == null)
            {
                return null;
            }

            var possibleEnds = new List<IRelationshipEnd>();
            foreach (var end in ParentElement.Relationship.Ends)
            {
                if (set.EntityType.IsOfType(end.Type))
                {
                    possibleEnds.Add(end);
                }
            }

            if (possibleEnds.Count == 1)
            {
                return possibleEnds[0];
            }
            else if (possibleEnds.Count == 0)
            {
                // no matchs
                AddError(
                    ErrorCode.FailedInference, EdmSchemaErrorSeverity.Error,
                    Strings.InferRelationshipEndFailedNoEntitySetMatch(
                        set.Name, ParentElement.Name, ParentElement.Relationship.FQName, set.EntityType.FQName,
                        ParentElement.ParentElement.FQName));
            }
            else
            {
                // ambiguous
                AddError(
                    ErrorCode.FailedInference, EdmSchemaErrorSeverity.Error,
                    Strings.InferRelationshipEndAmbiguous(
                        set.Name, ParentElement.Name, ParentElement.Relationship.FQName, set.EntityType.FQName,
                        ParentElement.ParentElement.FQName));
            }

            return null;
        }
 /// <summary>
 ///     Converts an entity set from SOM to metadata
 /// </summary>
 /// <param name="set"> The SOM element to process </param>
 /// <param name="container"> </param>
 /// <returns> The entity set object resulting from the convert </returns>
 private static EntitySet GetEntitySet(EntityContainerEntitySet set, EntityContainer container)
 {
     return container.GetEntitySetByName(set.Name, false);
 }
        /// <summary>
        ///     validate the following negative scenarios:
        ///     ReturnType="Collection(EntityTypeA)"
        ///     ReturnType="Collection(EntityTypeA)" EntitySet="ESet.EType is not oftype EntityTypeA"
        ///     EntitySet="A"
        ///     ReturnType="Collection(ComplexTypeA)" EntitySet="something"
        ///     ReturnType="Collection(ComplexTypeA)", but the ComplexTypeA has a nested complexType property, this scenario will be handle in the runtime
        /// </summary>
        private void ValidateFunctionImportReturnType(
            SchemaElement owner, SchemaType returnType, EntityContainerEntitySet entitySet, bool entitySetPathDefined)
        {
            // If entity type, verify specification of entity set and that the type is appropriate for the entity set
            var entityType = returnType as SchemaEntityType;

            if (entitySet != null && entitySetPathDefined)
            {
                owner.AddError(
                    ErrorCode.FunctionImportEntitySetAndEntitySetPathDeclared,
                    EdmSchemaErrorSeverity.Error,
                    Strings.FunctionImportEntitySetAndEntitySetPathDeclared(FQName));
            }

            if (null != entityType)
            {
                // entity type
                if (null == entitySet)
                {
                    // ReturnType="Collection(EntityTypeA)"
                    owner.AddError(
                        ErrorCode.FunctionImportReturnsEntitiesButDoesNotSpecifyEntitySet,
                        EdmSchemaErrorSeverity.Error,
                        Strings.FunctionImportReturnEntitiesButDoesNotSpecifyEntitySet(FQName));
                }
                else if (null != entitySet.EntityType
                         && !entityType.IsOfType(entitySet.EntityType))
                {
                    // ReturnType="Collection(EntityTypeA)" EntitySet="ESet.EType is not oftype EntityTypeA"
                    owner.AddError(
                        ErrorCode.FunctionImportEntityTypeDoesNotMatchEntitySet,
                        EdmSchemaErrorSeverity.Error,
                        Strings.FunctionImportEntityTypeDoesNotMatchEntitySet(
                            FQName, entitySet.EntityType.FQName, entitySet.Name));
                }
            }
            else
            {
                // complex type
                var complexType = returnType as SchemaComplexType;
                if (complexType != null)
                {
                    if (entitySet != null || entitySetPathDefined)
                    {
                        // ReturnType="Collection(ComplexTypeA)" EntitySet="something"
                        owner.AddError(
                            ErrorCode.ComplexTypeAsReturnTypeAndDefinedEntitySet,
                            EdmSchemaErrorSeverity.Error,
                            owner.LineNumber,
                            owner.LinePosition,
                            Strings.ComplexTypeAsReturnTypeAndDefinedEntitySet(FQName, complexType.Name));
                    }
                }
                else
                {
                    Debug.Assert(
                        returnType == null || returnType is ScalarType || returnType is SchemaEnumType || returnType is Relationship,
                        "null return type, scalar return type, enum return type or relationship expected here.");

                    // scalar type or no return type
                    if (entitySet != null || entitySetPathDefined)
                    {
                        // EntitySet="A"
                        owner.AddError(
                            ErrorCode.FunctionImportSpecifiesEntitySetButDoesNotReturnEntityType,
                            EdmSchemaErrorSeverity.Error,
                            Strings.FunctionImportSpecifiesEntitySetButNotEntityType(FQName));
                    }
                }
            }
        }
Example #25
0
        // <summary>
        // validate the following negative scenarios:
        // ReturnType="Collection(EntityTypeA)"
        // ReturnType="Collection(EntityTypeA)" EntitySet="ESet.EType is not oftype EntityTypeA"
        // EntitySet="A"
        // ReturnType="Collection(ComplexTypeA)" EntitySet="something"
        // ReturnType="Collection(ComplexTypeA)", but the ComplexTypeA has a nested complexType property, this scenario will be handle in the runtime
        // </summary>
        private void ValidateFunctionImportReturnType(
            SchemaElement owner, SchemaType returnType, EntityContainerEntitySet entitySet, bool entitySetPathDefined)
        {
            // If entity type, verify specification of entity set and that the type is appropriate for the entity set
            var entityType = returnType as SchemaEntityType;

            if (entitySet != null && entitySetPathDefined)
            {
                owner.AddError(
                    ErrorCode.FunctionImportEntitySetAndEntitySetPathDeclared,
                    EdmSchemaErrorSeverity.Error,
                    Strings.FunctionImportEntitySetAndEntitySetPathDeclared(FQName));
            }

            if (null != entityType)
            {
                // entity type
                if (null == entitySet)
                {
                    // ReturnType="Collection(EntityTypeA)"
                    owner.AddError(
                        ErrorCode.FunctionImportReturnsEntitiesButDoesNotSpecifyEntitySet,
                        EdmSchemaErrorSeverity.Error,
                        Strings.FunctionImportReturnEntitiesButDoesNotSpecifyEntitySet(FQName));
                }
                else if (null != entitySet.EntityType &&
                         !entityType.IsOfType(entitySet.EntityType))
                {
                    // ReturnType="Collection(EntityTypeA)" EntitySet="ESet.EType is not oftype EntityTypeA"
                    owner.AddError(
                        ErrorCode.FunctionImportEntityTypeDoesNotMatchEntitySet,
                        EdmSchemaErrorSeverity.Error,
                        Strings.FunctionImportEntityTypeDoesNotMatchEntitySet(
                            FQName, entitySet.EntityType.FQName, entitySet.Name));
                }
            }
            else
            {
                // complex type
                var complexType = returnType as SchemaComplexType;
                if (complexType != null)
                {
                    if (entitySet != null || entitySetPathDefined)
                    {
                        // ReturnType="Collection(ComplexTypeA)" EntitySet="something"
                        owner.AddError(
                            ErrorCode.ComplexTypeAsReturnTypeAndDefinedEntitySet,
                            EdmSchemaErrorSeverity.Error,
                            owner.LineNumber,
                            owner.LinePosition,
                            Strings.ComplexTypeAsReturnTypeAndDefinedEntitySet(FQName, complexType.Name));
                    }
                }
                else
                {
                    Debug.Assert(
                        returnType == null || returnType is ScalarType || returnType is SchemaEnumType || returnType is Relationship,
                        "null return type, scalar return type, enum return type or relationship expected here.");

                    // scalar type or no return type
                    if (entitySet != null || entitySetPathDefined)
                    {
                        // EntitySet="A"
                        owner.AddError(
                            ErrorCode.FunctionImportSpecifiesEntitySetButDoesNotReturnEntityType,
                            EdmSchemaErrorSeverity.Error,
                            Strings.FunctionImportSpecifiesEntitySetButNotEntityType(FQName));
                    }
                }
            }
        }
Example #26
0
        internal void ResolveEntitySet(SchemaElement owner, string unresolvedEntitySet, ref EntityContainerEntitySet entitySet)
        {
            Debug.Assert(IsFunctionImport, "Only FunctionImport elkements specify EntitySets");
            Debug.Assert(null != _container, "function imports must know container");

            // resolve entity set
            if (null == entitySet &&
                null != unresolvedEntitySet)
            {
                entitySet = _container.FindEntitySet(unresolvedEntitySet);

                if (null == entitySet)
                {
                    owner.AddError(
                        ErrorCode.FunctionImportUnknownEntitySet,
                        EdmSchemaErrorSeverity.Error,
                        Strings.FunctionImportUnknownEntitySet(unresolvedEntitySet, FQName));
                }
            }
        }
        // <summary>
        // Create and add a EntityContainerEnd from the IRelationshipEnd provided
        // </summary>
        // <param name="relationshipEnd"> The relationship end of the end to add. </param>
        // <param name="entitySet"> The entitySet to associate with the relationship end. </param>
        protected override void AddEnd(IRelationshipEnd relationshipEnd, EntityContainerEntitySet entitySet)
        {
            DebugCheck.NotNull(relationshipEnd);
            Debug.Assert(!_relationshipEnds.ContainsKey(relationshipEnd.Name));
            // we expect set to be null sometimes

            var end = new EntityContainerAssociationSetEnd(this);
            end.Role = relationshipEnd.Name;
            end.RelationshipEnd = relationshipEnd;

            end.EntitySet = entitySet;
            if (end.EntitySet != null)
            {
                _relationshipEnds.Add(end.Role, end);
            }
        }
Example #28
0
 protected abstract void AddEnd(
     IRelationshipEnd relationshipEnd,
     EntityContainerEntitySet entitySet);
Example #29
0
 public EntityContainerEntitySetDefiningQuery(EntityContainerEntitySet parentElement)
     : base((SchemaElement)parentElement, (IDbDependencyResolver)null)
 {
 }
 /// <summary>
 ///     Constructs an EntityContainerEntitySet
 /// </summary>
 /// <param name="parentElement"> Reference to the schema element. </param>
 public EntityContainerEntitySetDefiningQuery(EntityContainerEntitySet parentElement)
     : base(parentElement)
 {
 }
        internal void ResolveEntitySet(SchemaElement owner, string unresolvedEntitySet, ref EntityContainerEntitySet entitySet)
        {
            Debug.Assert(IsFunctionImport, "Only FunctionImport elkements specify EntitySets");
            Debug.Assert(null != _container, "function imports must know container");

            // resolve entity set
            if (null == entitySet
                && null != unresolvedEntitySet)
            {
                entitySet = _container.FindEntitySet(unresolvedEntitySet);

                if (null == entitySet)
                {
                    owner.AddError(
                        ErrorCode.FunctionImportUnknownEntitySet,
                        EdmSchemaErrorSeverity.Error,
                        Strings.FunctionImportUnknownEntitySet(unresolvedEntitySet, FQName));
                }
            }
        }
 private void HandleEntitySetElement(XmlReader reader)
 {
     DebugCheck.NotNull(reader);
     var set = new EntityContainerEntitySet(this);
     set.Parse(reader);
     Members.Add(set, true, Strings.DuplicateEntityContainerMemberName);
 }
 private void ValidateFunctionImportReturnType(
     SchemaElement owner, SchemaType returnType, CollectionKind returnTypeCollectionKind, EntityContainerEntitySet entitySet,
     bool entitySetPathDefined)
 {
     if (returnType != null
         && !ReturnTypeMeetsFunctionImportBasicRequirements(returnType, returnTypeCollectionKind))
     {
         owner.AddError(
             ErrorCode.FunctionImportUnsupportedReturnType,
             EdmSchemaErrorSeverity.Error,
             owner,
             GetReturnTypeErrorMessage(Name)
             );
     }
     ValidateFunctionImportReturnType(owner, returnType, entitySet, entitySetPathDefined);
 }
        private static bool TypeIsSubTypeOf(
            SchemaEntityType itemType, Dictionary<SchemaEntityType, EntityContainerEntitySet> baseEntitySetTypes,
            out EntityContainerEntitySet set)
        {
            if (itemType.IsTypeHierarchyRoot)
            {
                // can't be a sub type if we are a base type
                set = null;
                return false;
            }

            // walk up the hierarchy looking for a base that is the base type of an entityset
            for (var baseType = itemType.BaseType as SchemaEntityType; baseType != null; baseType = baseType.BaseType as SchemaEntityType)
            {
                if (baseEntitySetTypes.ContainsKey(baseType))
                {
                    set = baseEntitySetTypes[baseType];
                    return true;
                }
            }

            set = null;
            return false;
        }
        // <summary>
        // Adds a child EntitySet's tableKey (Schema/Table combination) to the validation collection
        // This is used to validate that no child EntitySets share a Schema.Table combination
        // </summary>
        private void CheckForDuplicateTableMapping(HashSet<string> tableKeys, EntityContainerEntitySet entitySet)
        {
            string schema;
            string table;

            if (String.IsNullOrEmpty(entitySet.DbSchema))
            {
                // if there is no specified DbSchema, use the parent EntityContainer's name
                schema = Name;
            }
            else
            {
                schema = entitySet.DbSchema;
            }

            if (String.IsNullOrEmpty(entitySet.Table))
            {
                // if there is no specified Table, use the EntitySet's name
                table = entitySet.Name;
            }
            else
            {
                table = entitySet.Table;
            }

            // create a key using the DbSchema and Table
            var tableKey = String.Format(CultureInfo.InvariantCulture, "{0}.{1}", schema, table);
            if (entitySet.DefiningQuery != null)
            {
                // don't consider the schema name for defining queries, because
                // we can't say for sure that it is the same as the entity container
                // so in this example
                //
                // <EntityContainer Name="dbo">
                //   <EntitySet Name="ByVal">
                //     <DefiningQuery>Select col1 from dbi.ByVal</DefiningQuery>
                //   </EntitySet>
                //   <EntitySet Name="ByVal1" Table="ByVal"/>
                //   ...
                //
                // ByVal and ByVal1 should not conflict in our check
                tableKey = entitySet.Name;
            }

            var alreadyExisted = !tableKeys.Add(tableKey);
            if (alreadyExisted)
            {
                entitySet.AddError(
                    ErrorCode.AlreadyDefined, EdmSchemaErrorSeverity.Error, Strings.DuplicateEntitySetTable(entitySet.Name, schema, table));
            }
        }
 // <summary>
 // Constructs an EntityContainerEntitySet
 // </summary>
 // <param name="parentElement"> Reference to the schema element. </param>
 public EntityContainerEntitySetDefiningQuery(EntityContainerEntitySet parentElement)
     : base(parentElement)
 {
 }
        /// <summary>
        ///     Used during the resolve phase to resolve the type name to the object that represents that type
        /// </summary>
        internal override void ResolveTopLevelNames()
        {
            base.ResolveTopLevelNames();

            if (_entitySet == null)
            {
                _entitySet = ParentElement.ParentElement.FindEntitySet(_unresolvedEntitySetName);
                if (_entitySet == null)
                {
                    AddError(
                        ErrorCode.InvalidEndEntitySet, EdmSchemaErrorSeverity.Error,
                        Strings.InvalidEntitySetNameReference(_unresolvedEntitySetName, Name));
                }
            }
        }
 protected abstract void AddEnd(IRelationshipEnd relationshipEnd, EntityContainerEntitySet entitySet);
        /// <summary>
        ///     Converts an entity set from SOM to metadata
        /// </summary>
        /// <param name="set"> The SOM element to process </param>
        /// <param name="providerManifest"> The provider manifest to be used for conversion </param>
        /// <param name="convertedItemCache"> The item collection for currently existing metadata objects </param>
        /// <param name="newGlobalItems"> The new GlobalItem objects that are created as a result of this conversion </param>
        /// <returns> The entity set object resulting from the convert </returns>
        private static EntitySet ConvertToEntitySet(
            EntityContainerEntitySet set,
            DbProviderManifest providerManifest,
            ConversionCache convertedItemCache,
            Dictionary<SchemaElement, GlobalItem> newGlobalItems)
        {
            var entitySet = new EntitySet(
                set.Name, set.DbSchema, set.Table, set.DefiningQuery,
                (EntityType)LoadSchemaElement(
                    set.EntityType,
                    providerManifest,
                    convertedItemCache,
                    newGlobalItems));

            // Extract the optional Documentation
            if (set.Documentation != null)
            {
                entitySet.Documentation = ConvertToDocumentation(set.Documentation);
            }
            AddOtherContent(set, entitySet);

            return entitySet;
        }