/// <summary>
        /// Initializes a new instance of the <see cref="ODataSerializerContext"/> class.
        /// </summary>
        /// <param name="entity">The entity whose navigation property is being expanded.</param>
        /// <param name="selectExpandClause">The <see cref="SelectExpandClause"/> for the navigation property being expanded.</param>
        /// <param name="navigationProperty">The navigation property being expanded.</param>
        /// <remarks>This constructor is used to construct the serializer context for writing expanded properties.</remarks>
        public ODataSerializerContext(EntityInstanceContext entity, SelectExpandClause selectExpandClause, IEdmNavigationProperty navigationProperty)
        {
            if (entity == null)
            {
                throw Error.ArgumentNull("entity");
            }
            if (navigationProperty == null)
            {
                throw Error.ArgumentNull("navigationProperty");
            }

            ODataSerializerContext context = entity.SerializerContext;

            Request         = context.Request;
            RequestContext  = context.RequestContext;
            Url             = context.Url;
            EntitySet       = context.EntitySet;
            Model           = context.Model;
            Path            = context.Path;
            RootElementName = context.RootElementName;
            SkipExpensiveAvailabilityChecks = context.SkipExpensiveAvailabilityChecks;
            MetadataLevel = context.MetadataLevel;
            Items         = context.Items;

            ExpandedEntity     = entity;
            SelectExpandClause = selectExpandClause;
            NavigationProperty = navigationProperty;
            EntitySet          = context.EntitySet.FindNavigationTarget(navigationProperty);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ODataSerializerContext"/> class.
        /// </summary>
        /// <param name="entity">The entity whose navigation property is being expanded.</param>
        /// <param name="selectExpandClause">The <see cref="SelectExpandClause"/> for the navigation property being expanded.</param>
        /// <param name="navigationProperty">The navigation property being expanded.</param>
        /// <remarks>This constructor is used to construct the serializer context for writing expanded properties.</remarks>
        public ODataSerializerContext(EntityInstanceContext entity, SelectExpandClause selectExpandClause, IEdmNavigationProperty navigationProperty)
        {
            if (entity == null)
            {
                throw Error.ArgumentNull("entity");
            }
            if (navigationProperty == null)
            {
                throw Error.ArgumentNull("navigationProperty");
            }

            ODataSerializerContext context = entity.SerializerContext;

            Request = context.Request;
            Url = context.Url;
            EntitySet = context.EntitySet;
            Model = context.Model;
            Path = context.Path;
            RootElementName = context.RootElementName;
            SkipExpensiveAvailabilityChecks = context.SkipExpensiveAvailabilityChecks;
            MetadataLevel = context.MetadataLevel;

            ExpandedEntity = entity;
            SelectExpandClause = selectExpandClause;
            NavigationProperty = navigationProperty;
            EntitySet = context.EntitySet.FindNavigationTarget(navigationProperty);
        }
        /// <summary>
        /// Sets the parsed <see cref="SelectExpandClause"/> for the <see cref="ODataMediaTypeFormatter"/> to use
        /// while writing response for this request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="selectExpandClause">The parsed <see cref="SelectExpandClause"/> of the given request.</param>
        public static void SetSelectExpandClause(this HttpRequestMessage request, SelectExpandClause selectExpandClause)
        {
            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }
            if (selectExpandClause == null)
            {
                throw Error.ArgumentNull("selectExpandClause");
            }

            request.Properties[SelectExpandClauseKey] = selectExpandClause;
        }