dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.8k stars 3.2k forks source link

Issue in IReverseEngineerScaffolder.ScaffoldModel() #35099

Closed MaxIliashenko closed 1 week ago

MaxIliashenko commented 1 week ago

File a bug

After updating my .NET and EF Core to version 9, the scaffolding is broken

Include your code

My scaffolding code is

        var scaffold = CreateMssqlScaffolder(navProperties);

        var dbOpts = new DatabaseModelFactoryOptions(tables: tables);
        var modelOpts = new ModelReverseEngineerOptions() { UseDatabaseNames = true };
        var codeGenOpts = new ModelCodeGenerationOptions
        {
            RootNamespace = appNamespace,
            ContextName = "AppDbContext",
            ContextNamespace = $"{appNamespace}.EfEntities",
            ModelNamespace = $"{appNamespace}.EfEntities",
            SuppressConnectionStringWarning = true,
            UseDataAnnotations = true,
            UseNullableReferenceTypes = true
        };

        var scaffoldedModelSources = scaffold.ScaffoldModel(connectionString, dbOpts, modelOpts, codeGenOpts);
        scaffoldedModelSources
            .AdditionalFiles
            .ToList()
            .ForEach(file => file.Path = Path.Combine("EFModel", file.Path));

Include stack traces

Method not found: 'Void Microsoft.EntityFrameworkCore.Scaffolding.ScaffoldedFile..ctor()'.
   at EntityFrameworkCore.Scaffolding.Handlebars.HbsCSharpModelGenerator.GenerateModel(IModel model, ModelCodeGenerationOptions options)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineerScaffolder.ScaffoldModel(String connectionString, DatabaseModelFactoryOptions databaseOptions, ModelReverseEngineerOptions modelOptions, ModelCodeGenerationOptions codeOptions)
   at DBP.Server.Designer.DBPAppGenerator.DBPAppDbContext.GenerateDbContext(String connectionString, String[] tables, List`1 navProperties) in C:\Projects\dbp\Server\Designer\DBPAppGenerator\DBPAppDbContext.cs:line 42

Include provider and version information

EF Core version: 9.0.0 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: .NET 9.0 Operating system: Windows 11 IDE: JetBrains Rider 2024.3

MaxIliashenko commented 1 week ago

Found it. We're using library https://github.com/TrackableEntities/EntityFrameworkCore.Scaffolding.Handlebars It's not updated to .NET 9