private static StoreItemCollection LoadStoreItemCollection(DbProviderManifest providerManifest, string ssdlName) { Debug.Assert(providerManifest != null, "providerManifest != null"); Debug.Assert(!string.IsNullOrWhiteSpace(ssdlName), "ssdlName cannot be null or empty"); using (var ssdlReader = providerManifest.GetInformation(ssdlName)) { IList <EdmSchemaError> errors; var storeItemCollection = StoreItemCollection.Create( new[] { ssdlReader }, new ReadOnlyCollection <string>( new List <string> { GetProviderServicesInformationLocationPath( providerManifest.GetType().Assembly.FullName, ssdlName) }), DependencyResolver.Instance, out errors); ThrowOnError(errors); return(storeItemCollection); } }
public static StoreItemCollection CreateStoreItemCollection( string ssdl, Version targetFrameworkVersion, IDbDependencyResolver resolver, out IList <EdmSchemaError> edmErrors) { if (ssdl == null) { throw new ArgumentNullException("ssdl"); } if (targetFrameworkVersion == null) { throw new ArgumentNullException("targetFrameworkVersion"); } if (!EntityFrameworkVersion.IsValidVersion(targetFrameworkVersion)) { throw new ArgumentException( string.Format(CultureInfo.CurrentCulture, Resources.ErrorNonValidTargetVersion, targetFrameworkVersion), "targetFrameworkVersion"); } using (var textReader = new StringReader(ssdl)) { using (var ssdlReader = XmlReader.Create(textReader)) { return(StoreItemCollection.Create(new[] { ssdlReader }, null, resolver, out edmErrors)); } } }
private static StoreItemCollection LoadStoreItemCollection( EntityStoreSchemaGenerator entityStoreSchemaGenerator) { var xmlReader = RegurgitatingXmlWriter.Regurgitate( entityStoreSchemaGenerator.WriteStoreSchema); // TODO: do not ignore the errors IList <EdmSchemaError> theErrors; var storeItemCollection = StoreItemCollection.Create(new[] { xmlReader }, null, null, out theErrors); return(storeItemCollection); }
private StoreItemCollection ValidateStoreModel(EntityDesignArtifact designArtifact) { Debug.Assert(designArtifact != null, "designArtifact != null"); var artifactSet = designArtifact.ArtifactSet; if (designArtifact.StorageModel == null) { artifactSet.AddError( new ErrorInfo( ErrorInfo.Severity.ERROR, Resources.ErrorValidatingArtifact_StorageModelMissing, designArtifact, ErrorCodes.ErrorValidatingArtifact_StorageModelMissing, ErrorClass.Runtime_SSDL)); return(null); } if (SchemaManager.GetSchemaVersion(designArtifact.StorageModel.XElement.Name.Namespace) > _targetEntityFrameworkRuntimeVersion) { // the xml namespace of the ssdl Schema node is for a later version of the runtime than we are validating against artifactSet.AddError( new ErrorInfo( ErrorInfo.Severity.ERROR, Resources.ErrorValidatingArtifact_InvalidSSDLNamespaceForTargetFrameworkVersion, designArtifact.StorageModel, ErrorCodes.ErrorValidatingArtifact_InvalidSSDLNamespaceForTargetFrameworkVersion, ErrorClass.Runtime_CSDL)); return(null); } using (var reader = CreateXmlReader(designArtifact, designArtifact.StorageModel.XElement)) { IList <EdmSchemaError> storeErrors; var storeItemCollection = StoreItemCollection.Create(new[] { reader }, null, _dependencyResolver, out storeErrors); Debug.Assert(storeErrors != null); // also process cached errors and warnings (if any) from reverse engineering db ProcessErrors( storeErrors.Concat(designArtifact.GetModelGenErrors() ?? Enumerable.Empty <EdmSchemaError>()), designArtifact, ErrorClass.Runtime_SSDL); return(storeItemCollection); } }
public static StoreItemCollection CreateStoreItemCollection(string ssdl) { var mockResolver = new Mock <IDbDependencyResolver>(); mockResolver.Setup( r => r.GetService( It.Is <Type>(t => t == typeof(DbProviderServices)), It.IsAny <string>())).Returns(SqlProviderServices.Instance); IList <EdmSchemaError> errors; return(StoreItemCollection.Create( new[] { XmlReader.Create(new StringReader(ssdl)) }, null, mockResolver.Object, out errors)); }
public void MyTest() { var names = new[] { "Simple", "Strings", "AllClrTypes", "GuidIdentity", "DateTime", "CompositeKey", "InverseMapping", "OneToMany", "ManyToMany", "AdventureWorks" }; //var reverse = new ReverseEngineerCodeFirstHandler(); foreach (var name in names) { // Load store schema var storeGenerator = new EntityStoreSchemaGenerator( "System.Data.SqlClient", $"Server=localhost;Database={name};Trusted_Connection=True;", "dbo"); storeGenerator.GenerateForeignKeyProperties = true; var errors = storeGenerator.GenerateStoreMetadata(Test.StoreMetadataFilters) .Where(x => x.Severity == System.Data.Metadata.Edm.EdmSchemaErrorSeverity.Error) .ToArray(); storeGenerator.WriteStoreSchema(@"c:\temp\" + name + ".ssdl"); //errors.HandleErrors(Strings.ReverseEngineer_SchemaError); var reader = XmlReader.Create(@"c:\temp\" + name + ".ssdl"); IList <EdmSchemaError> theErrors; var storeItemCollection = StoreItemCollection.Create(new[] { reader }, null, null, out theErrors); //var storeItemCollection = new System.Data.Metadata.Edm.StoreItemCollection(new[] { reader }); //var blahCC = new EntityModelSchemaGenerator(storeItemCollection, "My", "Default"); //blahCC.PluralizationService = PluralizationService.CreateService(new CultureInfo("en")); //blahCC.GenerateForeignKeyProperties = true; //blahCC.GenerateMetadata(); //MetadataWorkspace workspace = new MetadataWorkspace( // () => storeItemCollection, // null, // null); var blahB1 = storeItemCollection.GetEntityContainer("dboContainer"); var blahB2 = storeItemCollection.OfType <EntityType>().ToArray(); // Generate default mapping var contextName = "MyContext"; var modelGenerator = new EntityModelSchemaGenerator(storeGenerator.EntityContainer, "DefaultNamespace", contextName); modelGenerator.PluralizationService = PluralizationService.CreateService(new CultureInfo("en")); modelGenerator.GenerateForeignKeyProperties = true; modelGenerator.GenerateMetadata(); modelGenerator.WriteModelSchema(@"C:\temp\" + name + ".csdl"); modelGenerator.WriteStorageMapping(@"c:\temp\" + name + ".msdl"); } // Pull out info about types to be generated //var entityTypes = modelGenerator.EdmItemCollection.OfType<EntityType>().ToArray(); //var mappings = new ReverseEngineerCodeFirstHandler.EdmMapping(modelGenerator, storeItemCollection); //var contextHost = new EfTextTemplateHost //{ // EntityContainer = modelGenerator.EntityContainer, // Namespace = "MyNamespace", // ModelsNamespace = "MyNamespace.Model", // MappingNamespace = "MyNamespace.Mapping", // EntityFrameworkVersion = new Version(5,0), //}; //var templateProcessor = new TemplateProcessor(); //var contextContents = templateProcessor.ProcessContext(contextHost); //foreach (var entityType in entityTypes) //{ // // Generate the code file // var entityHost = new EfTextTemplateHost // { // EntityType = entityType, // EntityContainer = modelGenerator.EntityContainer, // Namespace = "MyNamespace", // ModelsNamespace = "MyNamespace.Model", // MappingNamespace = "MyNamespace.Mapping", // EntityFrameworkVersion = new Version(5, 0), // TableSet = mappings.EntityMappings[entityType].Item1, // PropertyToColumnMappings = mappings.EntityMappings[entityType].Item2, // ManyToManyMappings = mappings.ManyToManyMappings // }; // var entityContents = templateProcessor.ProcessEntity(entityHost); //} //foreach (var entityType in entityTypes) //{ // var mappingHost = new EfTextTemplateHost // { // EntityType = entityType, // EntityContainer = modelGenerator.EntityContainer, // Namespace = "MyNamespace", // ModelsNamespace = "MyNamespace.Model", // MappingNamespace = "MyNamespace.Mapping", // EntityFrameworkVersion = new Version(5, 0), // TableSet = mappings.EntityMappings[entityType].Item1, // PropertyToColumnMappings = mappings.EntityMappings[entityType].Item2, // ManyToManyMappings = mappings.ManyToManyMappings // }; // var mappingContents = templateProcessor.ProcessMapping(mappingHost); //} //reverse.ReverseEngineerCodeFirst(); Assert.True(true); }