コード例 #1
0
        private void VisitComplexOrEntityInstance(ComplexInstance payloadElement)
        {
            var entitySet = this.MetadataStack.Peek() as EntitySet;

            if (entitySet != null)
            {
                payloadElement.AddAnnotationIfNotExist(new EntitySetAnnotation()
                {
                    EntitySet = entitySet
                });

                // start with the entity type from the set
                var entityType = entitySet.EntityType;

                // if the payload has a type name in it, and its different from the entity type on the set...
                if (payloadElement.FullTypeName != null && payloadElement.FullTypeName != entityType.FullName)
                {
                    // ... then go find the more specific type in the model and use that instead (if it exists)
                    var specificEntityType = entitySet.Container.Model.EntityTypes.SingleOrDefault(t => t.IsKindOf(entityType) && t.FullName == payloadElement.FullTypeName);
                    if (specificEntityType != null)
                    {
                        entityType = specificEntityType;
                    }
                }

                if (entityType != null)
                {
                    payloadElement.AddAnnotationIfNotExist(new DataTypeAnnotation()
                    {
                        DataType = DataTypes.EntityType.WithDefinition(entityType)
                    });
                    this.VisitMemberProperties(payloadElement, entityType.AllProperties);
                    this.VisitNavigationProperties(payloadElement.Properties, entityType.AllNavigationProperties);
                }
            }
            else
            {
                var dataType = this.MetadataStack.Peek() as ComplexDataType;
                ExceptionUtilities.CheckObjectNotNull(dataType, "Expected complex data type, got '{0}'", this.MetadataStack.Peek());
                payloadElement.AddAnnotationIfNotExist(new DataTypeAnnotation()
                {
                    DataType = dataType
                });
                this.VisitMemberProperties(payloadElement, dataType.Definition.Properties);
            }
        }
コード例 #2
0
        private void VisitComplexOrEntityInstance(ComplexInstance payloadElement)
        {
            var entitySet = this.MetadataStack.Peek() as EntitySet;
            if (entitySet != null)
            {
                payloadElement.AddAnnotationIfNotExist(new EntitySetAnnotation() { EntitySet = entitySet });

                // start with the entity type from the set
                var entityType = entitySet.EntityType;

                // if the payload has a type name in it, and its different from the entity type on the set...
                if (payloadElement.FullTypeName != null && payloadElement.FullTypeName != entityType.FullName)
                {
                    // ... then go find the more specific type in the model and use that instead (if it exists)
                    var specificEntityType = entitySet.Container.Model.EntityTypes.SingleOrDefault(t => t.IsKindOf(entityType) && t.FullName == payloadElement.FullTypeName);
                    if (specificEntityType != null)
                    {
                        entityType = specificEntityType;
                    }
                }

                if (entityType != null)
                {
                    payloadElement.AddAnnotationIfNotExist(new DataTypeAnnotation() { DataType = DataTypes.EntityType.WithDefinition(entityType) });
                    this.VisitMemberProperties(payloadElement, entityType.AllProperties);
                    this.VisitNavigationProperties(payloadElement.Properties, entityType.AllNavigationProperties);
                }
            }
            else
            {
                var dataType = this.MetadataStack.Peek() as ComplexDataType;
                ExceptionUtilities.CheckObjectNotNull(dataType, "Expected complex data type, got '{0}'", this.MetadataStack.Peek());
                payloadElement.AddAnnotationIfNotExist(new DataTypeAnnotation() { DataType = dataType });
                this.VisitMemberProperties(payloadElement, dataType.Definition.Properties);
            }
        }