/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public virtual IReadOnlyCollection <ScaffoldedFile> GenerateModel( IModel model, CompiledModelCodeGenerationOptions options) { var scaffoldedFiles = new List <ScaffoldedFile>(); var modelCode = CreateModel(options.ModelNamespace, options.ContextType, options.UseNullableReferenceTypes); var modelFileName = options.ContextType.ShortDisplayName() + ModelSuffix + FileExtension; scaffoldedFiles.Add(new ScaffoldedFile { Path = modelFileName, Code = modelCode }); var entityTypeIds = new Dictionary <IEntityType, (string Variable, string Class)>(); var modelBuilderCode = CreateModelBuilder( model, options.ModelNamespace, options.ContextType, entityTypeIds, options.UseNullableReferenceTypes); var modelBuilderFileName = options.ContextType.ShortDisplayName() + ModelBuilderSuffix + FileExtension; scaffoldedFiles.Add(new ScaffoldedFile { Path = modelBuilderFileName, Code = modelBuilderCode }); foreach (var(entityType, (_, @class)) in entityTypeIds) { var generatedCode = GenerateEntityType( entityType, options.ModelNamespace, @class, options.UseNullableReferenceTypes); var entityTypeFileName = @class + FileExtension; scaffoldedFiles.Add(new ScaffoldedFile { Path = entityTypeFileName, Code = generatedCode }); } return(scaffoldedFiles); }
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> public virtual IReadOnlyList <string> ScaffoldModel( IModel model, string outputDir, CompiledModelCodeGenerationOptions options) { Check.NotNull(model, nameof(model)); Check.NotEmpty(outputDir, nameof(outputDir)); Check.NotNull(options, nameof(options)); var codeGenerator = ModelCodeGeneratorSelector.Select(options); var scaffoldedModel = codeGenerator.GenerateModel(model, options); CheckOutputFiles(scaffoldedModel, outputDir); Directory.CreateDirectory(outputDir); var savedFiles = new List <string>(); foreach (var file in scaffoldedModel) { var filePath = Path.Combine(outputDir, file.Path); File.WriteAllText(filePath, file.Code, Encoding.UTF8); savedFiles.Add(filePath); } return(savedFiles); }
/// <inheritdoc/> public virtual ICompiledModelCodeGenerator Select(CompiledModelCodeGenerationOptions options) => base.Select(options.Language, Services);