예제 #1
0
        static EntityDesignerUtils()
        {
            EFNamespaceSet set = new EFNamespaceSet {
                Edmx = "http://schemas.microsoft.com/ado/2007/06/edmx",
                Csdl = "http://schemas.microsoft.com/ado/2006/04/edm",
                Msl  = "urn:schemas-microsoft-com:windows:storage:mapping:CS",
                Ssdl = "http://schemas.microsoft.com/ado/2006/04/edm/ssdl"
            };

            v1Namespaces = set;
            set          = new EFNamespaceSet {
                Edmx = "http://schemas.microsoft.com/ado/2008/10/edmx",
                Csdl = "http://schemas.microsoft.com/ado/2008/09/edm",
                Msl  = "http://schemas.microsoft.com/ado/2008/09/mapping/cs",
                Ssdl = "http://schemas.microsoft.com/ado/2009/02/edm/ssdl"
            };
            v2Namespaces = set;
            set          = new EFNamespaceSet {
                Edmx = "http://schemas.microsoft.com/ado/2009/11/edmx",
                Csdl = "http://schemas.microsoft.com/ado/2009/11/edm",
                Msl  = "http://schemas.microsoft.com/ado/2009/11/mapping/cs",
                Ssdl = "http://schemas.microsoft.com/ado/2009/11/edm/ssdl"
            };
            v3Namespaces       = set;
            _edmxFileExtension = ".edmx";
        }
예제 #2
0
        internal static void ExtractConceptualMappingAndStorageNodes(StreamReader edmxInputStream, out XmlElement conceptualSchemaNode, out XmlElement mappingNode, out XmlElement storageSchemaNode, out string metadataArtifactProcessingValue)
        {
            XmlDocument document = new XmlDocument();

            using (XmlReader reader = XmlReader.Create(edmxInputStream))
            {
                document.Load(reader);
            }
            EFNamespaceSet set = v3Namespaces;

            if (document.DocumentElement.NamespaceURI == v2Namespaces.Edmx)
            {
                set = v2Namespaces;
            }
            else if (document.DocumentElement.NamespaceURI == v1Namespaces.Edmx)
            {
                set = v1Namespaces;
            }
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(document.NameTable);

            nsmgr.AddNamespace("edmx", set.Edmx);
            nsmgr.AddNamespace("edm", set.Csdl);
            nsmgr.AddNamespace("ssdl", set.Ssdl);
            nsmgr.AddNamespace("map", set.Msl);
            conceptualSchemaNode            = (XmlElement)document.SelectSingleNode("/edmx:Edmx/edmx:Runtime/edmx:ConceptualModels/edm:Schema", nsmgr);
            storageSchemaNode               = (XmlElement)document.SelectSingleNode("/edmx:Edmx/edmx:Runtime/edmx:StorageModels/ssdl:Schema", nsmgr);
            mappingNode                     = (XmlElement)document.SelectSingleNode("/edmx:Edmx/edmx:Runtime/edmx:Mappings/map:Mapping", nsmgr);
            metadataArtifactProcessingValue = string.Empty;
            XmlNodeList list = document.SelectNodes("/edmx:Edmx/edmx:Designer/edmx:Connection/edmx:DesignerInfoPropertySet/edmx:DesignerProperty", nsmgr);

            if (list != null)
            {
                foreach (XmlNode node in list)
                {
                    foreach (XmlAttribute attribute in node.Attributes)
                    {
                        if (attribute.Name.Equals("Name", StringComparison.Ordinal) && attribute.Value.Equals("MetadataArtifactProcessing", StringComparison.OrdinalIgnoreCase))
                        {
                            foreach (XmlAttribute attribute2 in node.Attributes)
                            {
                                if (attribute2.Name.Equals("Value", StringComparison.Ordinal))
                                {
                                    metadataArtifactProcessingValue = attribute2.Value;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Extract the Conceptual, Mapping and Storage nodes from an EDMX input streams, and extract the value of the metadataArtifactProcessing property.
        /// </summary>
        /// <param name="edmxInputStream"></param>
        /// <param name="conceptualSchemaNode"></param>
        /// <param name="mappingNode"></param>
        /// <param name="storageSchemaNode"></param>
        ///
        internal static void ExtractConceptualMappingAndStorageNodes(StreamReader edmxInputStream,
                                                                     out XmlElement conceptualSchemaNode, out XmlElement mappingNode, out XmlElement storageSchemaNode, out string metadataArtifactProcessingValue)
        {
            // load up an XML document representing the edmx file
            XmlDocument xmlDocument = new XmlDocument();

            using (var reader = XmlReader.Create(edmxInputStream))
            {
                xmlDocument.Load(reader);
            }

            EFNamespaceSet set = v3Namespaces;

            if (xmlDocument.DocumentElement.NamespaceURI == v2Namespaces.Edmx)
            {
                set = v2Namespaces;
            }
            else if (xmlDocument.DocumentElement.NamespaceURI == v1Namespaces.Edmx)
            {
                set = v1Namespaces;
            }

            XmlNamespaceManager nsMgr = new XmlNamespaceManager(xmlDocument.NameTable);

            nsMgr.AddNamespace("edmx", set.Edmx);
            nsMgr.AddNamespace("edm", set.Csdl);
            nsMgr.AddNamespace("ssdl", set.Ssdl);
            nsMgr.AddNamespace("map", set.Msl);

            // find the ConceptualModel Schema node
            conceptualSchemaNode = (XmlElement)xmlDocument.SelectSingleNode(
                "/edmx:Edmx/edmx:Runtime/edmx:ConceptualModels/edm:Schema", nsMgr);

            // find the StorageModel Schema node
            storageSchemaNode = (XmlElement)xmlDocument.SelectSingleNode(
                "/edmx:Edmx/edmx:Runtime/edmx:StorageModels/ssdl:Schema", nsMgr);

            // find the Mapping node
            mappingNode = (XmlElement)xmlDocument.SelectSingleNode(
                "/edmx:Edmx/edmx:Runtime/edmx:Mappings/map:Mapping", nsMgr);

            // find the Connection node

            metadataArtifactProcessingValue = String.Empty;
            XmlNodeList connectionProperties = xmlDocument.SelectNodes(
                "/edmx:Edmx/edmx:Designer/edmx:Connection/edmx:DesignerInfoPropertySet/edmx:DesignerProperty", nsMgr);

            if (connectionProperties != null)
            {
                foreach (XmlNode propertyNode in connectionProperties)
                {
                    foreach (XmlAttribute a in propertyNode.Attributes)
                    {
                        // treat attribute names case-sensitive (since it is xml), but attribute value case-insensitive to be accommodating .
                        if (a.Name.Equals("Name", StringComparison.Ordinal) && a.Value.Equals("MetadataArtifactProcessing", StringComparison.OrdinalIgnoreCase))
                        {
                            foreach (XmlAttribute a2 in propertyNode.Attributes)
                            {
                                if (a2.Name.Equals("Value", StringComparison.Ordinal))
                                {
                                    metadataArtifactProcessingValue = a2.Value;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }