/// <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 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 string WriteCode( [NotNull] ModelConfiguration modelConfiguration) { Check.NotNull(modelConfiguration, nameof(modelConfiguration)); _model = modelConfiguration; _sb = new IndentedStringBuilder(); _sb.AppendLine("using System;"); // Guid default values require new Guid() which requires this using _sb.AppendLine("using Microsoft.EntityFrameworkCore;"); _sb.AppendLine("using Microsoft.EntityFrameworkCore.Metadata;"); _sb.AppendLine(); _sb.AppendLine("namespace " + _model.Namespace()); _sb.AppendLine("{"); using (_sb.Indent()) { AddClass(); } _sb.Append("}"); return _sb.ToString(); }