コード例 #1
0
            protected override ItemCollection CreateItemCollection(IEnumerable <XmlReader> readers, out IList <EdmSchemaError> errors)
            {
                List <XmlReader> ownedReaders = new List <XmlReader>();
                List <XmlReader> allReaders   = new List <XmlReader>();

                try
                {
                    allReaders.AddRange(readers);
                    foreach (string path in _referenceSchemas.Distinct())
                    {
                        XElement reference;
                        if (TryLoadRootElement(path, out reference))
                        {
                            XmlReader reader = reference.CreateReader();
                            allReaders.Add(reader);
                            ownedReaders.Add(reader);
                        }
                    }

                    return(MetadataItemCollectionFactory.CreateEdmItemCollection(allReaders, out errors));
                }
                finally
                {
                    foreach (XmlReader reader in ownedReaders)
                    {
                        ((IDisposable)reader).Dispose();
                    }
                }
            }
コード例 #2
0
        private static void ValidateAndGenerateViews(FileInfo edmxFile, LanguageOption languageOption, bool generateViews)
        {
            XDocument xdoc = XDocument.Load(edmxFile.FullName);
            XElement  c    = GetCsdlFromEdmx(xdoc);
            XElement  s    = GetSsdlFromEdmx(xdoc);
            XElement  m    = GetMslFromEdmx(xdoc);
            Version   v    = _namespaceManager.GetVersionFromEDMXDocument(xdoc);

            // load the csdl
            XmlReader[]            cReaders          = { c.CreateReader() };
            IList <EdmSchemaError> cErrors           = null;
            EdmItemCollection      edmItemCollection =
                MetadataItemCollectionFactory.CreateEdmItemCollection(cReaders, out cErrors);

            // load the ssdl
            XmlReader[]            sReaders            = { s.CreateReader() };
            IList <EdmSchemaError> sErrors             = null;
            StoreItemCollection    storeItemCollection =
                MetadataItemCollectionFactory.CreateStoreItemCollection(sReaders, out sErrors);

            // load the msl
            XmlReader[]                  mReaders = { m.CreateReader() };
            IList <EdmSchemaError>       mErrors  = null;
            StorageMappingItemCollection mappingItemCollection =
                MetadataItemCollectionFactory.CreateStorageMappingItemCollection(
                    edmItemCollection, storeItemCollection, mReaders, out mErrors);

            // either pre-compile views or validate the mappings
            IList <EdmSchemaError> viewGenerationErrors = null;

            if (generateViews)
            {
                // generate views & write them out to a file
                string outputFile =
                    GetFileNameWithNewExtension(edmxFile, ".GeneratedViews" +
                                                GetFileExtensionForLanguageOption(languageOption));
                EntityViewGenerator evg = new EntityViewGenerator(languageOption);
                using (var file = File.OpenWrite(outputFile))
                {
                    using (var writer = new StreamWriter(file))
                    {
                        viewGenerationErrors =
                            evg.GenerateViews(mappingItemCollection, writer, v);
                    }
                }
            }
            else
            {
                viewGenerationErrors = EntityViewGenerator.Validate(mappingItemCollection, v);
            }

            // write errors
            WriteErrors(cErrors);
            WriteErrors(sErrors);
            WriteErrors(mErrors);
            WriteErrors(viewGenerationErrors);
        }
コード例 #3
0
ファイル: EdmxUtility.cs プロジェクト: dotnet/ef6tools
        public StorageMappingItemCollection GetMappingCollection()
        {
            IList <EdmSchemaError> errors;
            var edmxFileName = Path.GetFileName(_edmxPath);

            EdmItemCollection edmCollection;

            using (var reader = CreateSectionReader(EdmxSection.Csdl))
            {
                edmCollection = MetadataItemCollectionFactory.CreateEdmItemCollection(
                    new[] { reader },
                    out errors);
                errors.HandleErrors(Strings.EdmSchemaError(edmxFileName, EdmxSection.Csdl.SectionName));
            }

            StoreItemCollection storeCollection;

            using (var reader = CreateSectionReader(EdmxSection.Ssdl))
            {
                storeCollection = MetadataItemCollectionFactory.CreateStoreItemCollection(
                    new[] { reader },
                    out errors);
                errors.HandleErrors(Strings.EdmSchemaError(edmxFileName, EdmxSection.Ssdl.SectionName));
            }

            StorageMappingItemCollection mappingCollection;

            using (var reader = CreateSectionReader(EdmxSection.Msl))
            {
                mappingCollection = MetadataItemCollectionFactory.CreateStorageMappingItemCollection(
                    edmCollection,
                    storeCollection,
                    new[] { reader },
                    out errors);
                errors.HandleErrors(Strings.EdmSchemaError(edmxFileName, EdmxSection.Msl.SectionName));
            }

            return(mappingCollection);
        }
コード例 #4
0
 protected override ItemCollection CreateItemCollection(IEnumerable <XmlReader> readers, out IList <EdmSchemaError> errors)
 {
     return(MetadataItemCollectionFactory.CreateStoreItemCollection(readers, out errors));
 }