/// <summary>
        /// Deserializes an edmx response payload into a metadata payload representation
        /// </summary>
        /// <param name="edmxElement">The root of the edmx document</param>
        /// <returns>The metadata payload representation</returns>
        private MetadataPayloadElement DeserializeMetadata(XElement edmxElement)
        {
            ExceptionUtilities.CheckArgumentNotNull(edmxElement, "edmxElement");
            ExceptionUtilities.Assert(edmxElement.Name.LocalName == EdmxElementName, "Deserialize metadata must be called on the 'edmx' element");

            var edmxNamespace = edmxElement.Name.Namespace;

            // Find Version attribute on metadataElement
            XAttribute versionAttribute = edmxElement.Attribute("Version");

            ExceptionUtilities.CheckObjectNotNull(versionAttribute, "Could not find 'Version' attribute");
            string edmxVersion = versionAttribute.Value;

            // Find dataservice element
            XElement dataServicesElement = edmxElement.Element(edmxNamespace.GetName("DataServices"));

            ExceptionUtilities.CheckObjectNotNull(dataServicesElement, "Could not find 'DataServices' element");

            MetadataPayloadElement metadataPayload = new MetadataPayloadElement()
            {
                EdmxVersion = edmxVersion,
            };

            AddXmlBaseAnnotation(metadataPayload, edmxElement);

            XElement[] schemaElements = dataServicesElement.Elements().Where(e => e.Name.LocalName == "Schema").ToArray();

            ExceptionUtilities.CheckObjectNotNull(this.CsdlParser, "Cannot deserialize metadata without a CSDL parser.");
            var model = this.CsdlParser.Parse(schemaElements);

            metadataPayload.EntityModelSchema = model;
            foreach (XElement schemaElement in schemaElements)
            {
                string edmNamespace    = schemaElement.Name.NamespaceName;
                string schemaNamespace = schemaElement.Attributes().Where(a => a.Name.LocalName == "Namespace").Single().Value;
                model.Annotations.Add(new SchemaNamespaceAnnotation()
                {
                    EdmNamespaceVersion = edmNamespace, SchemaNamespace = schemaNamespace
                });
            }

            return(metadataPayload);
        }
        /// <summary>
        /// Deserializes an edmx response payload into a metadata payload representation
        /// </summary>
        /// <param name="edmxElement">The root of the edmx document</param>
        /// <returns>The metadata payload representation</returns>
        private MetadataPayloadElement DeserializeMetadata(XElement edmxElement)
        {
            ExceptionUtilities.CheckArgumentNotNull(edmxElement, "edmxElement");
            ExceptionUtilities.Assert(edmxElement.Name.LocalName == EdmxElementName, "Deserialize metadata must be called on the 'edmx' element");

            var edmxNamespace = edmxElement.Name.Namespace;

            // Find Version attribute on metadataElement
            XAttribute versionAttribute = edmxElement.Attribute("Version");
            ExceptionUtilities.CheckObjectNotNull(versionAttribute, "Could not find 'Version' attribute");
            string edmxVersion = versionAttribute.Value;

            // Find dataservice element
            XElement dataServicesElement = edmxElement.Element(edmxNamespace.GetName("DataServices"));
            ExceptionUtilities.CheckObjectNotNull(dataServicesElement, "Could not find 'DataServices' element");

            MetadataPayloadElement metadataPayload = new MetadataPayloadElement()
            {
                EdmxVersion = edmxVersion,
            };

            AddXmlBaseAnnotation(metadataPayload, edmxElement);

            XElement[] schemaElements = dataServicesElement.Elements().Where(e => e.Name.LocalName == "Schema").ToArray();
            
            ExceptionUtilities.CheckObjectNotNull(this.CsdlParser, "Cannot deserialize metadata without a CSDL parser.");
            var model = this.CsdlParser.Parse(schemaElements);
            metadataPayload.EntityModelSchema = model;
            foreach (XElement schemaElement in schemaElements)
            {
                string edmNamespace = schemaElement.Name.NamespaceName;
                string schemaNamespace = schemaElement.Attributes().Where(a => a.Name.LocalName == "Namespace").Single().Value;
                model.Annotations.Add(new SchemaNamespaceAnnotation() { EdmNamespaceVersion = edmNamespace, SchemaNamespace = schemaNamespace });
            }

            return metadataPayload;
        }