Пример #1
0
        /// <summary>
        /// Reads an EDMX file from a stream.
        /// </summary>
        /// <param name="edmxStream">Stream to read the EDMX data from.</param>
        public EDMXFile(System.IO.Stream edmxStream)
        {
            //load edmx stream
            _edmxDocument = new XmlDocument();
            _edmxDocument.Load(edmxStream);

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

            //ensure the file is in the expected format...
            switch (_edmxVersion)
            {
            case EDMXVersionEnum.EDMX2012:
            case EDMXVersionEnum.EDMX2010:
                //expected format
                break;

            case EDMXVersionEnum.EDMX2008:
                throw new NotSupportedException("The EDMX file is in VS2008 / EFv1 format. This tool only support VS2010/EFv4 EDMX files");

            //break;
            default:
                throw new NotSupportedException("Unknown EDMX file format.");
            }
        }
Пример #2
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;
        }