Reversing a postgres database using EF Core 6 fails
See original GitHub issueDescribe what is not working as expected.
Steps to reproduce
When I try to Reverse a postgres database using EF Core 6 it fails with the following error
System.Exception: Reverse engineer error:
System.ArgumentNullException: Value cannot be null. (Parameter 'property')
at string Microsoft.EntityFrameworkCore.RelationalPropertyExtensions.GetColumnName(IReadOnlyProperty property, in StoreObjectIdentifier storeObject)
at string Npgsql.EntityFrameworkCore.PostgreSQL.Metadata.Internal.NpgsqlAnnotationProvider+<>c__DisplayClass3_0.<For>b__0(?)+(string p) => { }
at TResult[] System.Linq.Enumerable+SelectArrayIterator<TSource, TResult>.ToArray()
at TSource[] System.Linq.Enumerable.ToArray<TSource>(IEnumerable<TSource> source)
at IEnumerable<IAnnotation> Npgsql.EntityFrameworkCore.PostgreSQL.Metadata.Internal.NpgsqlAnnotationProvider.For(ITableIndex index, bool designTime)+MoveNext()
at void Microsoft.EntityFrameworkCore.Infrastructure.AnnotatableBase.AddAnnotations(AnnotatableBase annotatable, IEnumerable<IAnnotation> annotations) x 2
at IRelationalModel Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.Create(IModel model, IRelationalAnnotationProvider relationalAnnotationProvider, bool designTime)
at IModel Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.Add(IModel model, IRelationalAnnotationProvider relationalAnnotationProvider, bool designTime)
at void Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelRuntimeInitializer.InitializeModel(IModel model, bool designTime, bool prevalidation)
at IModel Microsoft.EntityFrameworkCore.Infrastructure.ModelRuntimeInitializer.Initialize(IModel model, bool designTime, IDiagnosticsLogger<Validation> validationLogger)
at IModel Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.Create(DatabaseModel databaseModel, ModelReverseEngineerOptions options)
at ScaffoldedModel RevEng.Core.ReverseEngineerScaffolder.ScaffoldModel(string connectionString, DatabaseModelFactoryOptions databaseOptions, ModelReverseEngineerOptions modelOptions, ModelCodeGenerationOptions codeOptions, bool removeNullableBoolDefaults, bool excludeNavigations, bool dbContextOnly, bool entitiesOnly, bool useSchemaFolders, ServiceProvider serviceProvider) in C:/Code/EFCorePowerTools/src/GUI/RevEng.Core/ReverseEngineerScaffolder.cs:line 216
at SavedModelFiles RevEng.Core.ReverseEngineerScaffolder.GenerateDbContext(ReverseEngineerCommandOptions options, ServiceProvider serviceProvider, List<string> schemas, string outputContextDir, string modelNamespace, string contextNamespace) in C:/Code/EFCorePowerTools/src/GUI/RevEng.Core/ReverseEngineerScaffolder.cs:line 62
at ReverseEngineerResult RevEng.Core.ReverseEngineerRunner.GenerateFiles(ReverseEngineerCommandOptions options) in C:/Code/EFCorePowerTools/src/GUI/RevEng.Core/ReverseEngineerRunner.cs:line 93
at int efreveng.Program.Main(string[] args) in C:/Code/EFCorePowerTools/src/GUI/efreveng/Program.cs:line 58
at ReverseEngineerResult EFCorePowerTools.Handlers.ReverseEngineer.ResultDeserializer.BuildResult(string output)
at async Task<ReverseEngineerResult> EFCorePowerTools.Handlers.ReverseEngineer.EfRevEngLauncher.GetOutputAsync()
at async Task<ReverseEngineerResult> EFCorePowerTools.Handlers.ReverseEngineer.EfRevEngLauncher.LaunchExternalRunnerAsync(ReverseEngineerOptions options, CodeGenerationMode codeGenerationMode)
at async Task EFCorePowerTools.Handlers.ReverseEngineer.ReverseEngineerHandler.GenerateFilesAsync(Project project, ReverseEngineerOptions options, Tuple<bool, string> containsEfCoreReference)
at async Task EFCorePowerTools.Handlers.ReverseEngineer.ReverseEngineerHandler.ReverseEngineerCodeFirstAsync(Project project, string optionsPath, bool onlyGenerate)
System.Exception: Reverse engineer error:
System.ArgumentNullException: Value cannot be null. (Parameter 'property')
at string Microsoft.EntityFrameworkCore.RelationalPropertyExtensions.GetColumnName(IReadOnlyProperty property, in StoreObjectIdentifier storeObject)
at string Npgsql.EntityFrameworkCore.PostgreSQL.Metadata.Internal.NpgsqlAnnotationProvider+<>c__DisplayClass3_0.<For>b__0(?)+(string p) => { }
at TResult[] System.Linq.Enumerable+SelectArrayIterator<TSource, TResult>.ToArray()
at TSource[] System.Linq.Enumerable.ToArray<TSource>(IEnumerable<TSource> source)
at IEnumerable<IAnnotation> Npgsql.EntityFrameworkCore.PostgreSQL.Metadata.Internal.NpgsqlAnnotationProvider.For(ITableIndex index, bool designTime)+MoveNext()
at void Microsoft.EntityFrameworkCore.Infrastructure.AnnotatableBase.AddAnnotations(AnnotatableBase annotatable, IEnumerable<IAnnotation> annotations) x 2
at IRelationalModel Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.Create(IModel model, IRelationalAnnotationProvider relationalAnnotationProvider, bool designTime)
at IModel Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalModel.Add(IModel model, IRelationalAnnotationProvider relationalAnnotationProvider, bool designTime)
at void Microsoft.EntityFrameworkCore.Infrastructure.RelationalModelRuntimeInitializer.InitializeModel(IModel model, bool designTime, bool prevalidation)
at IModel Microsoft.EntityFrameworkCore.Infrastructure.ModelRuntimeInitializer.Initialize(IModel model, bool designTime, IDiagnosticsLogger<Validation> validationLogger)
at IModel Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.Create(DatabaseModel databaseModel, ModelReverseEngineerOptions options)
at ScaffoldedModel RevEng.Core.ReverseEngineerScaffolder.ScaffoldModel(string connectionString, DatabaseModelFactoryOptions databaseOptions, ModelReverseEngineerOptions modelOptions, ModelCodeGenerationOptions codeOptions, bool removeNullableBoolDefaults, bool excludeNavigations, bool dbContextOnly, bool entitiesOnly, bool useSchemaFolders, ServiceProvider serviceProvider) in C:/Code/EFCorePowerTools/src/GUI/RevEng.Core/ReverseEngineerScaffolder.cs:line 216
at SavedModelFiles RevEng.Core.ReverseEngineerScaffolder.GenerateDbContext(ReverseEngineerCommandOptions options, ServiceProvider serviceProvider, List<string> schemas, string outputContextDir, string modelNamespace, string contextNamespace) in C:/Code/EFCorePowerTools/src/GUI/RevEng.Core/ReverseEngineerScaffolder.cs:line 62
at ReverseEngineerResult RevEng.Core.ReverseEngineerRunner.GenerateFiles(ReverseEngineerCommandOptions options) in C:/Code/EFCorePowerTools/src/GUI/RevEng.Core/ReverseEngineerRunner.cs:line 93
at int efreveng.Program.Main(string[] args) in C:/Code/EFCorePowerTools/src/GUI/efreveng/Program.cs:line 58
at ReverseEngineerResult EFCorePowerTools.Handlers.ReverseEngineer.ResultDeserializer.BuildResult(string output)
at async Task<ReverseEngineerResult> EFCorePowerTools.Handlers.ReverseEngineer.EfRevEngLauncher.GetOutputAsync()
at async Task<ReverseEngineerResult> EFCorePowerTools.Handlers.ReverseEngineer.EfRevEngLauncher.LaunchExternalRunnerAsync(ReverseEngineerOptions options, CodeGenerationMode codeGenerationMode)
at async Task EFCorePowerTools.Handlers.ReverseEngineer.ReverseEngineerHandler.GenerateFilesAsync(Project project, ReverseEngineerOptions options, Tuple<bool, string> containsEfCoreReference)
at async Task EFCorePowerTools.Handlers.ReverseEngineer.ReverseEngineerHandler.ReverseEngineerCodeFirstAsync(Project project, string optionsPath, bool onlyGenerate)
If I instead select EF Core 5 it works as expected
Further technical details
EF Core version in use: EF Core 6
EF Core Power Tools version: 2.5.832
Database engine: Postgres
Visual Studio version: Visual Studio 2022 17.0.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Entity Framework Models are not working after Reverse ...
I am getting the following error when I try to use the models: type or namespace name could not be found. c# ·...
Read more >Reverse engineering of Postgres 9.4 database fails in .NET 6
Calling ScaffoldModel() for Postgres 9.4 server database throws error column "collprovider" does not exist at character 32 in statement ...
Read more >Breaking changes in EF Core 6.0
Complete list of breaking changes introduced in Entity Framework Core 6.0.
Read more >Connect PostgreSQL to .NET 6 Web API using EF Core
In this tutorial, you will learn how to connect a PostgreSQL database to your .NET 6 application using Entity Framework Core and how...
Read more >Getting Started with Entity Framework Core (PostgreSQL)
Start reverse-engineering your database from the PostgreSQL database you created in Step 1 to Code Models. To do this execute the following: Using...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ErikEJ yes I get the same error when I use
dotnet ef scaffold
When i get some time i will see if i can figure out what caused the issue, but my suspension is that it was a index that included some fields, as i get some errors if i try to run my ef model with indexes that include fields.