/// <summary>
        /// Sets the expected property for the top-level property instance.
        /// </summary>
        /// <param name="property">The property instance to set the expected property for.</param>
        /// <param name="owningType">The type owning the expected property.</param>
        /// <param name="expectedPropertyName">The name of the property to set as the expected property.</param>
        /// <returns>The <paramref name="property"/> after its expected property was set.</returns>
        public static PropertyInstance ExpectedProperty(
            this PropertyInstance property,
            IEdmStructuredType owningType,
            string expectedPropertyName)
        {
            ExceptionUtilities.CheckArgumentNotNull(property, "property");
            ExceptionUtilities.CheckArgumentNotNull(owningType, "owningType");
            ExceptionUtilities.CheckStringArgumentIsNotNullOrEmpty(expectedPropertyName, "expectedPropertyName");

            ExpectedTypeODataPayloadElementAnnotation annotation = ODataPayloadElementExtensions.AddExpectedTypeAnnotation(property);

            annotation.EdmOwningType = owningType;
            var memberProperty = owningType.FindProperty(expectedPropertyName);

            if (memberProperty != null)
            {
                annotation.EdmProperty     = memberProperty;
                annotation.EdmExpectedType = memberProperty.Type;
            }
            else
            {
                ExceptionUtilities.Assert(owningType.IsOpen, "For non-declared properties the owning type must be open.");
                annotation.OpenMemberPropertyName = expectedPropertyName;
            }

            return(property);
        }
        /// <summary>
        /// Sets the expected base entity type for the top-level entity set.
        /// </summary>
        /// <param name="entitySetInstance">The entity set instance to set the expected set for.</param>
        /// <param name="entitySet">The entity set the entities belong to.</param>
        /// <param name="baseEntityType">The base entity type to set as the expected base entity type.</param>
        /// <returns>The <paramref name="entitySetInstance"/> after its expected type was set.</returns>
        public static EntitySetInstance ExpectedEntityType(this EntitySetInstance entitySetInstance, IEdmTypeReference baseEntityType, IEdmEntitySet entitySet = null)
        {
            ExceptionUtilities.CheckArgumentNotNull(entitySetInstance, "entitySetInstance");
            ExpectedTypeODataPayloadElementAnnotation annotation = ODataPayloadElementExtensions.AddExpectedTypeAnnotation(entitySetInstance);
            var entityType = baseEntityType ?? (entitySet == null ? null : entitySet.EntityType().ToTypeReference());

            annotation.EdmExpectedType = entityType;
            annotation.EdmEntitySet    = entitySet;
            return(entitySetInstance);
        }
 /// <summary>
 /// Sets the expected type for a primitive value.
 /// </summary>
 /// <typeparam name="T">The acutal primitive type.</typeparam>
 /// <param name="primitiveValue">The primitive value to set the expected type for.</param>
 /// <param name="primitiveDataType">The primitive type to set as the expected type.</param>
 /// <returns>The <paramref name="primitiveValue"/> after its expected type was set.</returns>
 public static T ExpectedPrimitiveValueType <T>(this T primitiveValue, IEdmPrimitiveTypeReference primitiveDataType) where T : PrimitiveValue
 {
     ExceptionUtilities.CheckArgumentNotNull(primitiveValue, "primitiveValue");
     ODataPayloadElementExtensions.AddExpectedTypeAnnotation(primitiveValue).EdmExpectedType = primitiveDataType;
     return(primitiveValue);
 }
 /// <summary>
 /// Sets the expected property type for the top-level property.
 /// </summary>
 /// <param name="property">The property instance to set the expected type for.</param>
 /// <param name="dataType">The type to set as the expected property type.</param>
 /// <returns>The <paramref name="property"/> after its expected type was set.</returns>
 public static PropertyInstance ExpectedPropertyType(this PropertyInstance property, IEdmType dataType, bool nullable = false)
 {
     ExceptionUtilities.CheckArgumentNotNull(property, "property");
     ODataPayloadElementExtensions.AddExpectedTypeAnnotation(property).EdmExpectedType = dataType.ToTypeReference(nullable);
     return(property);
 }