Esempio n. 1
0
        /// <summary>
        /// Creates a new EDMX file with the given model name, provider and provider manifest token.
        /// </summary>
        /// <param name="modelName">Name of the new model, e.g. "AdventureWorks".</param>
        /// <param name="dbProvider">Database provider name, e.g. "System.Data.SqlClient"</param>
        /// <param name="providerManifestToken">Provider manifest token, e.g. "2008"</param>
        /// <param name="version">EDMX file version</param>
        public EDMXFile(string modelName, string dbProvider, string providerManifestToken, EDMXVersionEnum version)
        {
            //new blank EDMX File
            _edmxDocument = new XmlDocument();

            string schemaURI = string.Empty;
            string versionNumber = string.Empty;
            switch (version)
            {
                case EDMXVersionEnum.EDMX2008:
                    schemaURI = "http://schemas.microsoft.com/ado/2007/06/edmx";
                    versionNumber = "1.0";
                    break;
                case EDMXVersionEnum.EDMX2010:
                    schemaURI = "http://schemas.microsoft.com/ado/2008/10/edmx";
                    versionNumber = "2.0";
                    break;
                case EDMXVersionEnum.EDMX2012:
                    schemaURI = "http://schemas.microsoft.com/ado/2009/11/edmx";
                    versionNumber = "3.0";
                    break;
            }

            //create document element
            XmlElement docElement = _edmxDocument.CreateElement("Edmx", schemaURI);
            docElement.SetAttribute("Version", versionNumber);
            _edmxDocument.AppendChild(docElement);

            //get hold of the namespace manager
            _nsm = EDMXUtils.GetNamespaceManager(_edmxDocument, out _edmxVersion);

            CreateEmptyEDMX();

            //set required storage model properties
            this.StorageModel.Namespace = modelName + ".Store";
            this.StorageModel.Provider = dbProvider;
            this.StorageModel.ProviderManifestToken = providerManifestToken;
            this.StorageModel.ContainerName = modelName + "StoreContainer";

            //set required conceptial model properties
            this.ConceptualModel.Namespace = modelName;
            this.ConceptualModel.ContainerName = modelName + "Entities";

            //set required mapping properties
            this.CSMapping.StorageEntityContainer = this.StorageModel.ContainerName;
            this.CSMapping.ConceptualEntityContainer = this.ConceptualModel.ContainerName;

            //set required designer properties
            this.Designer.DiagramName = modelName;
        }
Esempio n. 2
0
 internal static XmlNamespaceManager GetNamespaceManager(XmlDocument edmxFile, out EDMXVersionEnum edmxVersion)
 {
     XmlNamespaceManager nsm = new XmlNamespaceManager(edmxFile.NameTable);
     switch (edmxFile.DocumentElement.NamespaceURI)
     {
         case "http://schemas.microsoft.com/ado/2009/11/edmx":
             nsm.AddNamespace("edmx", "http://schemas.microsoft.com/ado/2009/11/edmx", edmxFile.DocumentElement);
             nsm.AddNamespace("store", "http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator", edmxFile.DocumentElement);
             nsm.AddNamespace("ssdl", "http://schemas.microsoft.com/ado/2009/11/edm/ssdl", edmxFile.DocumentElement);
             nsm.AddNamespace("edm", "http://schemas.microsoft.com/ado/2009/11/edm", edmxFile.DocumentElement);
             nsm.AddNamespace("annotation", "http://schemas.microsoft.com/ado/2009/02/edm/annotation", edmxFile.DocumentElement);
             nsm.AddNamespace("map", "http://schemas.microsoft.com/ado/2009/11/mapping/cs", edmxFile.DocumentElement);
             nsm.AddNamespace("codegen", "http://schemas.microsoft.com/ado/2006/04/codegeneration", edmxFile.DocumentElement);
             nsm.AddNamespace("huagati", "http://www.huagati.com/edmxtools/annotations", edmxFile.DocumentElement);
             edmxVersion = EDMXVersionEnum.EDMX2012;
             break;
         case "http://schemas.microsoft.com/ado/2008/10/edmx":
             nsm.AddNamespace("edmx", "http://schemas.microsoft.com/ado/2008/10/edmx", edmxFile.DocumentElement);
             nsm.AddNamespace("store", "http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator", edmxFile.DocumentElement);
             nsm.AddNamespace("ssdl", "http://schemas.microsoft.com/ado/2009/02/edm/ssdl", edmxFile.DocumentElement);
             nsm.AddNamespace("edm", "http://schemas.microsoft.com/ado/2008/09/edm", edmxFile.DocumentElement);
             nsm.AddNamespace("annotation", "http://schemas.microsoft.com/ado/2009/02/edm/annotation", edmxFile.DocumentElement);
             nsm.AddNamespace("map", "http://schemas.microsoft.com/ado/2008/09/mapping/cs", edmxFile.DocumentElement);
             nsm.AddNamespace("codegen", "http://schemas.microsoft.com/ado/2006/04/codegeneration", edmxFile.DocumentElement);
             nsm.AddNamespace("huagati", "http://www.huagati.com/edmxtools/annotations", edmxFile.DocumentElement);
             edmxVersion = EDMXVersionEnum.EDMX2010;
             break;
         case "http://schemas.microsoft.com/ado/2007/06/edmx":
             nsm.AddNamespace("edmx", "http://schemas.microsoft.com/ado/2007/06/edmx");
             nsm.AddNamespace("store", "http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator");
             nsm.AddNamespace("ssdl", "http://schemas.microsoft.com/ado/2006/04/edm/ssdl");
             nsm.AddNamespace("edm", "http://schemas.microsoft.com/ado/2006/04/edm");
             nsm.AddNamespace("map", "urn:schemas-microsoft-com:windows:storage:mapping:CS");
             edmxVersion = EDMXVersionEnum.EDMX2008;
             break;
         default:
             edmxVersion = EDMXVersionEnum.Unknown;
             break;
     }
     return nsm;
 }
Esempio n. 3
0
        /// <summary>
        /// Creates a new EDMX file with the given model name, provider and provider manifest token.
        /// </summary>
        /// <param name="modelName">Name of the new model, e.g. "AdventureWorks".</param>
        /// <param name="dbProvider">Database provider name, e.g. "System.Data.SqlClient"</param>
        /// <param name="providerManifestToken">Provider manifest token, e.g. "2008"</param>
        /// <param name="version">EDMX file version</param>
        public EDMXFile(string modelName, string dbProvider, string providerManifestToken, EDMXVersionEnum version)
        {
            //new blank EDMX File
            _edmxDocument = new XmlDocument();

            string schemaURI     = string.Empty;
            string versionNumber = string.Empty;

            switch (version)
            {
            case EDMXVersionEnum.EDMX2008:
                schemaURI     = "http://schemas.microsoft.com/ado/2007/06/edmx";
                versionNumber = "1.0";
                break;

            case EDMXVersionEnum.EDMX2010:
                schemaURI     = "http://schemas.microsoft.com/ado/2008/10/edmx";
                versionNumber = "2.0";
                break;

            case EDMXVersionEnum.EDMX2012:
                schemaURI     = "http://schemas.microsoft.com/ado/2009/11/edmx";
                versionNumber = "3.0";
                break;
            }

            //create document element
            XmlElement docElement = _edmxDocument.CreateElement("Edmx", schemaURI);

            docElement.SetAttribute("Version", versionNumber);
            _edmxDocument.AppendChild(docElement);

            //get hold of the namespace manager
            _nsm = EDMXUtils.GetNamespaceManager(_edmxDocument, out _edmxVersion);

            CreateEmptyEDMX();

            //set required storage model properties
            this.StorageModel.Namespace             = modelName + ".Store";
            this.StorageModel.Provider              = dbProvider;
            this.StorageModel.ProviderManifestToken = providerManifestToken;
            this.StorageModel.ContainerName         = modelName + "StoreContainer";

            //set required conceptial model properties
            this.ConceptualModel.Namespace     = modelName;
            this.ConceptualModel.ContainerName = modelName + "Entities";

            //set required mapping properties
            this.CSMapping.StorageEntityContainer    = this.StorageModel.ContainerName;
            this.CSMapping.ConceptualEntityContainer = this.ConceptualModel.ContainerName;

            //set required designer properties
            this.Designer.DiagramName = modelName;
        }
Esempio n. 4
0
        internal static XmlNamespaceManager GetNamespaceManager(XmlDocument edmxFile, out EDMXVersionEnum edmxVersion)
        {
            XmlNamespaceManager nsm = new XmlNamespaceManager(edmxFile.NameTable);

            switch (edmxFile.DocumentElement.NamespaceURI)
            {
            case "http://schemas.microsoft.com/ado/2009/11/edmx":
                nsm.AddNamespace("edmx", "http://schemas.microsoft.com/ado/2009/11/edmx", edmxFile.DocumentElement);
                nsm.AddNamespace("store", "http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator", edmxFile.DocumentElement);
                nsm.AddNamespace("ssdl", "http://schemas.microsoft.com/ado/2009/11/edm/ssdl", edmxFile.DocumentElement);
                nsm.AddNamespace("edm", "http://schemas.microsoft.com/ado/2009/11/edm", edmxFile.DocumentElement);
                nsm.AddNamespace("annotation", "http://schemas.microsoft.com/ado/2009/02/edm/annotation", edmxFile.DocumentElement);
                nsm.AddNamespace("map", "http://schemas.microsoft.com/ado/2009/11/mapping/cs", edmxFile.DocumentElement);
                nsm.AddNamespace("codegen", "http://schemas.microsoft.com/ado/2006/04/codegeneration", edmxFile.DocumentElement);
                nsm.AddNamespace("huagati", "http://www.huagati.com/edmxtools/annotations", edmxFile.DocumentElement);
                edmxVersion = EDMXVersionEnum.EDMX2012;
                break;

            case "http://schemas.microsoft.com/ado/2008/10/edmx":
                nsm.AddNamespace("edmx", "http://schemas.microsoft.com/ado/2008/10/edmx", edmxFile.DocumentElement);
                nsm.AddNamespace("store", "http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator", edmxFile.DocumentElement);
                nsm.AddNamespace("ssdl", "http://schemas.microsoft.com/ado/2009/02/edm/ssdl", edmxFile.DocumentElement);
                nsm.AddNamespace("edm", "http://schemas.microsoft.com/ado/2008/09/edm", edmxFile.DocumentElement);
                nsm.AddNamespace("annotation", "http://schemas.microsoft.com/ado/2009/02/edm/annotation", edmxFile.DocumentElement);
                nsm.AddNamespace("map", "http://schemas.microsoft.com/ado/2008/09/mapping/cs", edmxFile.DocumentElement);
                nsm.AddNamespace("codegen", "http://schemas.microsoft.com/ado/2006/04/codegeneration", edmxFile.DocumentElement);
                nsm.AddNamespace("huagati", "http://www.huagati.com/edmxtools/annotations", edmxFile.DocumentElement);
                edmxVersion = EDMXVersionEnum.EDMX2010;
                break;

            case "http://schemas.microsoft.com/ado/2007/06/edmx":
                nsm.AddNamespace("edmx", "http://schemas.microsoft.com/ado/2007/06/edmx");
                nsm.AddNamespace("store", "http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator");
                nsm.AddNamespace("ssdl", "http://schemas.microsoft.com/ado/2006/04/edm/ssdl");
                nsm.AddNamespace("edm", "http://schemas.microsoft.com/ado/2006/04/edm");
                nsm.AddNamespace("map", "urn:schemas-microsoft-com:windows:storage:mapping:CS");
                edmxVersion = EDMXVersionEnum.EDMX2008;
                break;

            default:
                edmxVersion = EDMXVersionEnum.Unknown;
                break;
            }
            return(nsm);
        }