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

NullReferenceException with EntityTypeTransformationService.TransformNavPropertyName #136

Closed
gdycus opened this issue Aug 17, 2020 · 14 comments · Fixed by #137
Closed

NullReferenceException with EntityTypeTransformationService.TransformNavPropertyName #136

gdycus opened this issue Aug 17, 2020 · 14 comments · Fixed by #137
Labels
bug Something isn't working

Comments

@gdycus
Copy link

gdycus commented Aug 17, 2020

Getting the following error when executing "dotnet ef dbcontext scaffold". Any thoughts on what might cause this error? Thanks!

System.NullReferenceException: Object reference not set to an instance of an object.
at EntityFrameworkCore.Scaffolding.Handlebars.HbsCSharpDbContextGenerator.GenerateRelationship(IForeignKey foreignKey, Boolean useDataAnnotations, IndentedStringBuilder sb)
at EntityFrameworkCore.Scaffolding.Handlebars.HbsCSharpDbContextGenerator.GenerateEntityType(IEntityType entityType, Boolean useDataAnnotations, IndentedStringBuilder sb)
at EntityFrameworkCore.Scaffolding.Handlebars.HbsCSharpDbContextGenerator.GenerateOnModelCreating(IModel model, Boolean useDataAnnotations)
at EntityFrameworkCore.Scaffolding.Handlebars.HbsCSharpDbContextGenerator.GenerateClass(IModel model, String contextName, String connectionString, Boolean useDataAnnotations, Boolean suppressConnectionStringWarning)
at EntityFrameworkCore.Scaffolding.Handlebars.HbsCSharpDbContextGenerator.WriteCode(IModel model, String contextName, String connectionString, String contextNamespace, String modelNamespace, Boolean useDataAnnotations, Boolean suppressConnectionStringWarning)
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 Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String outputContextDir, String dbContextClassName, IEnumerable1 schemas, IEnumerable1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable1 schemaFilters, IEnumerable1 tableFilters, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.b__0()

@gdycus gdycus added the question Further information is requested label Aug 17, 2020
@gdycus
Copy link
Author

gdycus commented Aug 17, 2020

I'm using 3.1.7 versions of EntityFrameworkCore components

@ErikEJ
Copy link
Contributor

ErikEJ commented Aug 17, 2020

Which version of the Handlebars package?

Which EF Core provider and version?

@gdycus
Copy link
Author

gdycus commented Aug 17, 2020

Microsoft.EntityFrameworkCore = 3.1.7
Microsoft.EntityFrameworkCore.Design = 3.1.7
Microsoft.EntityFrameworkCore.SqlServer = 3.1.7
Microsoft.EntityFrameworkCore.Tools = 3.1.7
EntityFrameworkCore.Scaffolding.Handlebars = 3.8.2

@ErikEJ
Copy link
Contributor

ErikEJ commented Aug 17, 2020

Possible related to ErikEJ/EFCorePowerTools#463

@ErikEJ
Copy link
Contributor

ErikEJ commented Aug 17, 2020

We need your database schema

@gdycus
Copy link
Author

gdycus commented Aug 17, 2020

I just emailed it to you @ErikEJ

@gdycus
Copy link
Author

gdycus commented Aug 17, 2020

@tonysneed could I send the schema to your private email? If so, could you send your email address?

@gdycus
Copy link
Author

gdycus commented Aug 17, 2020

Or you can email me at grady at singenuity com and I'll reply with the schema

FYI I do not have EF Power Tools installed

@tonysneed
Copy link
Contributor

tonysneed commented Aug 17, 2020

@gdycus If you run the command dotnet ef dbcontext scaffold, without involving Handlebars at all, you will get an error. So this is not a bug in Handlebars templates, but seems to be related to your model:

The column 'Merchandise.Products.Taxable' would normally be mapped to a non-nullable bool property, but it has a default constraint. Such a column is mapped to a nullable bool property to allow a difference between setting the property to false and invoking the default constraint. See https://go.microsoft.com/fwlink/?linkid=851278 for details.

@ErikEJ
Copy link
Contributor

ErikEJ commented Aug 18, 2020

Why would that warning cause a NRE?

@tonysneed tonysneed added bug Something isn't working and removed question Further information is requested labels Aug 18, 2020
@tonysneed
Copy link
Contributor

@ErikEJ You're right. The NRE takes place simply because I need to use the null propagation operator.
@gdycus I'll release a fix ASAP.

tonysneed added a commit that referenced this issue Aug 18, 2020
@tonysneed tonysneed changed the title System.NullReferenceException NullReferenceException with EntityTypeTransformationService.TransformNavPropertyName Aug 18, 2020
@tonysneed
Copy link
Contributor

tonysneed commented Aug 18, 2020

@ErikEJ @gdycus Fix has been published with release v3.8.3 on NuGet.

@ErikEJ
Copy link
Contributor

ErikEJ commented Aug 18, 2020

Perfect, I just updated EF Core Power Tools, and the fix is available in the latest daily build

@gdycus
Copy link
Author

gdycus commented Aug 18, 2020

It's working now. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants