public override Task<ReverseEngineerFiles> WriteCodeAsync( ModelConfiguration modelConfiguration, string outputPath, string dbContextClassName, CancellationToken cancellationToken = default(CancellationToken)) { Check.NotNull(modelConfiguration, nameof(modelConfiguration)); Check.NotEmpty(outputPath, nameof(outputPath)); Check.NotEmpty(dbContextClassName, nameof(dbContextClassName)); cancellationToken.ThrowIfCancellationRequested(); var resultingFiles = new ReverseEngineerFiles(); var generatedCode = DbContextWriter.WriteCode(modelConfiguration); // output DbContext .cs file var dbContextFileName = dbContextClassName + FileExtension; var dbContextFileFullPath = FileService.OutputFile( outputPath, dbContextFileName, generatedCode); resultingFiles.ContextFile = dbContextFileFullPath; foreach (var entityConfig in modelConfiguration.EntityConfigurations) { generatedCode = EntityTypeWriter.WriteCode(entityConfig); // output EntityType poco .cs file var entityTypeFileName = entityConfig.EntityType.DisplayName() + FileExtension; var entityTypeFileFullPath = FileService.OutputFile( outputPath, entityTypeFileName, generatedCode); resultingFiles.EntityTypeFiles.Add(entityTypeFileFullPath); } return Task.FromResult(resultingFiles); }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public virtual ReverseEngineerFiles Save( ScaffoldedModel scaffoldedModel, string projectPath, string outputPath, bool overwriteFiles) { Check.NotEmpty(projectPath, nameof(projectPath)); var outputDir = outputPath == null ? projectPath : Path.GetFullPath(Path.Combine(projectPath, outputPath)); CheckOutputFiles(scaffoldedModel, outputDir, overwriteFiles); var files = new ReverseEngineerFiles(); Directory.CreateDirectory(outputDir); var contextPath = Path.Combine(outputDir, scaffoldedModel.ContextFile.Path); File.WriteAllText(contextPath, scaffoldedModel.ContextFile.Code, Encoding.UTF8); files.ContextFile = contextPath; foreach (var entityTypeFile in scaffoldedModel.EntityTypeFiles) { var additionalFilePath = Path.Combine(outputDir, entityTypeFile.Path); File.WriteAllText(additionalFilePath, entityTypeFile.Code, Encoding.UTF8); files.EntityTypeFiles.Add(additionalFilePath); } return(files); }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public override ReverseEngineerFiles WriteCode( IModel model, string outputPath, string @namespace, string contextName, string connectionString, bool useDataAnnotations) { Check.NotNull(model, nameof(model)); Check.NotEmpty(outputPath, nameof(outputPath)); Check.NotEmpty(@namespace, nameof(@namespace)); Check.NotEmpty(contextName, nameof(contextName)); Check.NotEmpty(connectionString, nameof(connectionString)); var resultingFiles = new ReverseEngineerFiles(); var generatedCode = CSharpDbContextGenerator.WriteCode(model, @namespace, contextName, connectionString, useDataAnnotations); // output DbContext .cs file var dbContextFileName = contextName + FileExtension; var dbContextFileFullPath = FileService.OutputFile( outputPath, dbContextFileName, generatedCode); resultingFiles.ContextFile = dbContextFileFullPath; foreach (var entityType in model.GetEntityTypes()) { generatedCode = CSharpEntityTypeGenerator.WriteCode(entityType, @namespace, useDataAnnotations); // output EntityType poco .cs file var entityTypeFileName = entityType.DisplayName() + FileExtension; var entityTypeFileFullPath = FileService.OutputFile( outputPath, entityTypeFileName, generatedCode); resultingFiles.EntityTypeFiles.Add(entityTypeFileFullPath); } return(resultingFiles); }
public override Task <ReverseEngineerFiles> WriteCodeAsync( [NotNull] ModelConfiguration modelConfiguration, [NotNull] string outputPath, [NotNull] string dbContextClassName, CancellationToken cancellationToken = default(CancellationToken)) { Check.NotNull(modelConfiguration, nameof(modelConfiguration)); Check.NotEmpty(outputPath, nameof(outputPath)); Check.NotEmpty(dbContextClassName, nameof(dbContextClassName)); cancellationToken.ThrowIfCancellationRequested(); var resultingFiles = new ReverseEngineerFiles(); var generatedCode = DbContextWriter.WriteCode(modelConfiguration); // output DbContext .cs file var dbContextFileName = dbContextClassName + FileExtension; var dbContextFileFullPath = FileService.OutputFile( outputPath, dbContextFileName, generatedCode); resultingFiles.ContextFile = dbContextFileFullPath; foreach (var entityConfig in modelConfiguration.EntityConfigurations) { generatedCode = EntityTypeWriter.WriteCode(entityConfig); // output EntityType poco .cs file var entityTypeFileName = entityConfig.EntityType.DisplayName() + FileExtension; var entityTypeFileFullPath = FileService.OutputFile( outputPath, entityTypeFileName, generatedCode); resultingFiles.EntityTypeFiles.Add(entityTypeFileFullPath); } return(Task.FromResult(resultingFiles)); }