private static IList <EdmSchemaError> GetMinimumTargetFrameworkVersion(StorageMappingItemCollection mappingCollection, out Version targetFrameworkVersion) { List <EdmSchemaError> errorList = new List <EdmSchemaError>(); targetFrameworkVersion = EntityFrameworkVersionsUtil.ConvertToVersion(mappingCollection.EdmItemCollection.EdmVersion); if (targetFrameworkVersion > EntityFrameworkVersions.Default) { errorList.Add(new EdmSchemaError(Strings.DefaultTargetVersionTooLow(EntityFrameworkVersions.Default, targetFrameworkVersion), (int)System.Data.Entity.Design.SsdlGenerator.ModelBuilderErrorCode.SchemaVersionHigherThanTargetVersion, EdmSchemaErrorSeverity.Warning)); } return(errorList); }
public static EdmItemCollection CreateEdmItemCollection(IEnumerable <XmlReader> readers, Version targetEntityFrameworkVersion, out IList <EdmSchemaError> errors) { EDesignUtil.CheckTargetEntityFrameworkVersionArgument(targetEntityFrameworkVersion, "targetEntityFrameworkVersion"); EdmItemCollection edmItemCollection = CreateEdmItemCollection(readers, out errors); if (!errors.Any(e => e.Severity == EdmSchemaErrorSeverity.Error)) { ValidateActualVersionAgainstTarget(targetEntityFrameworkVersion, EntityFrameworkVersionsUtil.ConvertToVersion(edmItemCollection.EdmVersion), errors); } return(edmItemCollection); }
private static void CheckForCompatibleSchemaAndTarget(StorageMappingItemCollection mappingCollection, Version targetEntityFrameworkVersion) { Version mappingVersion = EntityFrameworkVersionsUtil.ConvertToVersion(mappingCollection.MappingVersion); if (targetEntityFrameworkVersion < mappingVersion) { throw EDesignUtil.Argument(Strings.TargetVersionSchemaVersionMismatch(targetEntityFrameworkVersion, mappingVersion), null); } Version edmVersion = EntityFrameworkVersionsUtil.ConvertToVersion(mappingCollection.EdmItemCollection.EdmVersion); if (targetEntityFrameworkVersion < edmVersion) { throw EDesignUtil.Argument(Strings.TargetVersionSchemaVersionMismatch(targetEntityFrameworkVersion, edmVersion), null); } }
private bool IsValidSchema(XmlReader reader, out Version entityFrameworkVersion) { double schemaVersion; DataSpace dataSpace; if (System.Data.EntityModel.SchemaObjectModel.SchemaManager.TryGetSchemaVersion(reader, out schemaVersion, out dataSpace) && dataSpace == DataSpace.CSpace) { entityFrameworkVersion = EntityFrameworkVersionsUtil.ConvertToVersion(schemaVersion); return(true); } else if (EntityFrameworkVersions.TryGetEdmxVersion(reader, out entityFrameworkVersion)) { return(true); } return(false); }
public static StorageMappingItemCollection CreateStorageMappingItemCollection( EdmItemCollection edmCollection, StoreItemCollection storeCollection, IEnumerable <XmlReader> readers, Version targetEntityFrameworkVersion, out IList <EdmSchemaError> errors) { EDesignUtil.CheckArgumentNull(edmCollection, "edmCollection"); EDesignUtil.CheckArgumentNull(storeCollection, "storeCollection"); EDesignUtil.CheckArgumentNull(readers, "readers"); EDesignUtil.CheckTargetEntityFrameworkVersionArgument(targetEntityFrameworkVersion, "targetEntityFrameworkVersion"); if (EntityFrameworkVersionsUtil.ConvertToVersion(edmCollection.EdmVersion) > targetEntityFrameworkVersion) { throw EDesignUtil.Argument("edmCollection"); } StorageMappingItemCollection storageMappingItemCollection = CreateStorageMappingItemCollection(edmCollection, storeCollection, readers, out errors); if (!errors.Any(e => e.Severity == EdmSchemaErrorSeverity.Error)) { ValidateActualVersionAgainstTarget(targetEntityFrameworkVersion, EntityFrameworkVersionsUtil.ConvertToVersion(storageMappingItemCollection.MappingVersion), errors); } return(storageMappingItemCollection); }
private void GenerateCodeCommon(MetadataArtifactLoader sourceLoader, List <MetadataArtifactLoader> loaders, LazyTextWriterCreator target, string sourceEdmSchemaFilePath, string targetFilePath, bool closeReaders, List <EdmSchemaError> errors) { MetadataArtifactLoaderComposite composite = new MetadataArtifactLoaderComposite(loaders); // create the schema manager from the xml readers Dictionary <MetadataArtifactLoader, XmlReader> readerSourceMap = new Dictionary <MetadataArtifactLoader, XmlReader>(); IList <Schema> schemas; List <XmlReader> readers = composite.GetReaders(readerSourceMap); try { IList <EdmSchemaError> schemaManagerErrors = SchemaManager.ParseAndValidate(readers, composite.GetPaths(), SchemaDataModelOption.EntityDataModel, EdmProviderManifest.Instance, out schemas); errors.AddRange(schemaManagerErrors); } finally { if (closeReaders) { MetadataUtil.DisposeXmlReaders(readers); } } ThrowOnAnyNonWarningErrors(errors); Debug.Assert(readerSourceMap.ContainsKey(sourceLoader), "the source loader didn't produce any of the xml readers..."); XmlReader sourceReader = readerSourceMap[sourceLoader]; // use the index of the "source" xml reader as the index of the "source" schema Debug.Assert(readers.Contains(sourceReader), "the source reader is not in the list of readers"); int index = readers.IndexOf(sourceReader); Debug.Assert(index >= 0, "couldn't find the source reader in the list of readers"); Debug.Assert(readers.Count == schemas.Count, "We have a different number of readers than schemas"); Schema sourceSchema = schemas[index]; Debug.Assert(sourceSchema != null, "sourceSchema is null"); // create the EdmItemCollection from the schemas EdmItemCollection itemCollection = new EdmItemCollection(schemas); if (EntityFrameworkVersionsUtil.ConvertToVersion(itemCollection.EdmVersion) >= EntityFrameworkVersions.Version2) { throw EDesignUtil.InvalidOperation(Strings.TargetEntityFrameworkVersionToNewForEntityClassGenerator); } // generate code ClientApiGenerator generator = new ClientApiGenerator(sourceSchema, itemCollection, this, errors); generator.GenerateCode(target, targetFilePath); }