Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EF Core 7 Reverse Engineer Error #1523

Closed
aespitia opened this issue Sep 20, 2022 · 27 comments
Closed

EF Core 7 Reverse Engineer Error #1523

aespitia opened this issue Sep 20, 2022 · 27 comments

Comments

@aespitia
Copy link

Error when reverse engineering a model from an existing DB:

Microsoft SQL Server 2014 12.0.6439.10 (X64)

using EFCore 7 RC1

System.InvalidOperationException: Reverse engineer error:
System.NullReferenceException: Object reference not set to an instance of an object.
at string Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpDbContextGenerator.TransformText()
at string Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpModelGenerator.ProcessTemplate(ITextTransformation transformation)
at ScaffoldedModel Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpModelGenerator.GenerateModel(IModel model, ModelCodeGenerationOptions 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) in C:/Code/Github/EFCorePowerTools/src/GUI/RevEng.Core/ReverseEngineerScaffolder.cs:line 374
at SavedModelFiles RevEng.Core.ReverseEngineerScaffolder.GenerateDbContext(ReverseEngineerCommandOptions options, List schemas, string outputContextDir, string modelNamespace, string contextNamespace) in C:/Code/Github/EFCorePowerTools/src/GUI/RevEng.Core/ReverseEngineerScaffolder.cs:line 99
at ReverseEngineerResult RevEng.Core.ReverseEngineerRunner.GenerateFiles(ReverseEngineerCommandOptions options) in C:/Code/Github/EFCorePowerTools/src/GUI/RevEng.Core/ReverseEngineerRunner.cs:line 93
at int EfReveng.Program.Main(string[] args) in C:/Code/Github/EFCorePowerTools/src/GUI/efreveng/Program.cs:line 68

at ReverseEngineerResult EFCorePowerTools.Handlers.ReverseEngineer.ResultDeserializer.BuildResult(string output)
at async Task EFCorePowerTools.Handlers.ReverseEngineer.EfRevEngLauncher.GetOutputAsync()
at async Task EFCorePowerTools.Handlers.ReverseEngineer.EfRevEngLauncher.LaunchExternalRunnerAsync(ReverseEngineerOptions options, CodeGenerationMode codeGenerationMode, Project project)
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, bool fromSqlProj)

@ErikEJ
Copy link
Owner

ErikEJ commented Sep 20, 2022

Are you using the T4 templates. Try to rename / delete the CodeTemplates folder.

@ErikEJ
Copy link
Owner

ErikEJ commented Sep 21, 2022

Ping?

@aespitia
Copy link
Author

aespitia commented Sep 21, 2022

Are you using the T4 templates. Try to rename / delete the CodeTemplates folder.

from what i can tell, i am not using T4 templates. i have a working model if generated using the EF6 option, this error comes from the EF7 preview option when reverse engineering.

i don't see a codeTemplates folder to remove.

I'm using EF Core Power Tools 2.5.1142.0 on VS 2022

@ErikEJ
Copy link
Owner

ErikEJ commented Sep 21, 2022

I am unable to repro locally, can you share the database schema, for example via a .dacpac and your efpt.config.json file?

@aespitia
Copy link
Author

I've removed the tables, but there are tables in 3 different schemas, as well as views, functions, and stored procs. object types 0, 1, 2, and 3.

{
"CodeGenerationMode": 3,
"ContextClassName": "Context",
"ContextNamespace": "",
"DefaultDacpacSchema": null,
"FilterSchemas": false,
"IncludeConnectionString": false,
"ModelNamespace": null,
"OutputContextPath": "",
"OutputPath": "Generated",
"PreserveCasingWithRegex": true,
"ProjectRootNamespace": "Project.Domain",
"Schemas": null,
"SelectedHandlebarsLanguage": 0,
"SelectedToBeGenerated": 0,
"UiHint": "SERVER.DBNAME",
"UseBoolPropertiesWithoutDefaultSql": true,
"UseDatabaseNames": false,
"UseDbContextSplitting": true,
"UseFluentApiOnly": false,
"UseHandleBars": false,
"UseHierarchyId": false,
"UseInflector": true,
"UseLegacyPluralizer": true,
"UseManyToManyEntity": false,
"UseNoConstructor": false,
"UseNoDefaultConstructor": false,
"UseNoNavigations": false,
"UseNoObjectFilter": false,
"UseNodaTime": false,
"UseNullableReferences": true,
"UseSchemaFolders": false,
"UseSpatial": false,
"UseT4": false
}

@ErikEJ
Copy link
Owner

ErikEJ commented Sep 21, 2022

I need the database schema (either .sql script or bacpac file)

@aespitia
Copy link
Author

I can't send the schema, but i'll see if I can recreate it in a dummy schema in a new project

@aespitia
Copy link
Author

aespitia commented Sep 21, 2022

dbproject.zip

this project seems to throw the error for me if i try pointing to the dacpac

@ErikEJ
Copy link
Owner

ErikEJ commented Sep 22, 2022

With the same error? I am not able to repro that (.dacpac functionality is currently borken with EF Core 7)

@ErikEJ
Copy link
Owner

ErikEJ commented Sep 22, 2022

Alos not able to repro if I publish the database project

@aespitia
Copy link
Author

OK, yes, I got a different error from the dacpac, not the same as the original. will tweak the sample project some more to see if I can narrow down the cause.

@ErikEJ
Copy link
Owner

ErikEJ commented Sep 22, 2022

Yeah, sorry, but .dacpac support for EF Core 7 is currently pending

@aespitia
Copy link
Author

Is there any log or output you can turn on to see what the progress was to see what the last thing was that it was trying to reverse engineer?

@ErikEJ
Copy link
Owner

ErikEJ commented Sep 22, 2022

No, once you figure out (or share the full schema privately) I will try to address this with the EF Core team (lack of good error message)

@ErikEJ
Copy link
Owner

ErikEJ commented Sep 22, 2022

You could try to use the EF Core 7 command line tool, and run it with verbose logging.

@ErikEJ
Copy link
Owner

ErikEJ commented Sep 26, 2022

Any news?

@aespitia
Copy link
Author

dbproject.zip
Yes, try this one the issue is with the no-pk table. it has an FK, but no PK. will update the db on our end to see if it fixes the issue for me to get past this.

@aespitia
Copy link
Author

yes fixing the PK seems to fix it, the .net core 6 implementation does show the warning in the GUI over the table, but processes it fine

@ErikEJ
Copy link
Owner

ErikEJ commented Sep 26, 2022

@bricelam potential EF Core 7 issue?

@ErikEJ
Copy link
Owner

ErikEJ commented Sep 26, 2022

Could you share the EF 6 warning?

@aespitia
Copy link
Author

i just meant that in the GUI of ef Core POwertools there's a warning sign (yellow triangle) on the table that has no PK. but it processes it anyway.

@ErikEJ ErikEJ added reveng bug Something isn't working labels Oct 8, 2022
@ErikEJ
Copy link
Owner

ErikEJ commented Oct 10, 2022

@aespitia Unable to repro based on your latest .zip file

@ErikEJ ErikEJ added blocked and removed bug Something isn't working labels Oct 10, 2022
@ErikEJ
Copy link
Owner

ErikEJ commented Oct 11, 2022

Closing as no repro was provided

@ErikEJ ErikEJ closed this as not planned Won't fix, can't repro, duplicate, stale Oct 11, 2022
@blogcraft
Copy link

I happen to come across the same problem.

I have an app which uses some tables that don´t have a primary key.

When I do a reverse engineer with Ef Core 6, it works fine and generates the model correctly.

But when I choose Ef Core 7 the model generation fails with this error:

System.InvalidOperationException: Reverse engineer error: 
System.NullReferenceException: Object reference not set to an instance of an object.
   at string Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpDbContextGenerator.TransformText()
   at string Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpModelGenerator.ProcessTemplate(ITextTransformation transformation)
   at ScaffoldedModel Microsoft.EntityFrameworkCore.Scaffolding.Internal.CSharpModelGenerator.GenerateModel(IModel model, ModelCodeGenerationOptions 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) in C:/Code/Github/EFCorePowerTools/src/GUI/RevEng.Core/ReverseEngineerScaffolder.cs:line 385
   at SavedModelFiles RevEng.Core.ReverseEngineerScaffolder.GenerateDbContext(ReverseEngineerCommandOptions options, List<string> schemas, string outputContextDir, string modelNamespace, string contextNamespace, string projectPath, string outputPath) in C:/Code/Github/EFCorePowerTools/src/GUI/RevEng.Core/ReverseEngineerScaffolder.cs:line 103
   at ReverseEngineerResult RevEng.Core.ReverseEngineerRunner.GenerateFiles(ReverseEngineerCommandOptions options) in C:/Code/Github/EFCorePowerTools/src/GUI/RevEng.Core/ReverseEngineerRunner.cs:line 88
   at async Task<int> EfReveng.Program.Main(string[] args) in C:/Code/Github/EFCorePowerTools/src/GUI/efreveng/Program.cs:line 69

   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, Project project)
   at async Task EFCorePowerTools.Handlers.ReverseEngineer.ReverseEngineerHandler.GenerateFilesAsync(Project project, ReverseEngineerOptions options, Tuple<bool, string> containsEfCoreReference, bool onlyGenerate)
   at async Task EFCorePowerTools.Handlers.ReverseEngineer.ReverseEngineerHandler.ReverseEngineerCodeFirstAsync(Project project, string optionsPath, bool onlyGenerate, bool fromSqlProj)

I suspect the problem has to do with the tables without primary key because when I remove those tables from the reverse engineer process, it works.

@blogcraft
Copy link

Digging around, it seems that the problem is related to this and not a Power tools Issue?

dotnet/efcore#29516

@ErikEJ
Copy link
Owner

ErikEJ commented Jan 20, 2023

@blogcraft correct. And will be fixed in 7.0.3

@aespitia
Copy link
Author

yay! glad to know this issue helped someone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants