Closed gdycus closed 3 years ago
I'm using 3.1.7 versions of EntityFrameworkCore components
Which version of the Handlebars package?
Which EF Core provider and version?
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
Possible related to https://github.com/ErikEJ/EFCorePowerTools/issues/463
We need your database schema
I just emailed it to you @ErikEJ
@tonysneed could I send the schema to your private email? If so, could you send your email address?
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
@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.
Why would that warning cause a NRE?
@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.
Perfect, I just updated EF Core Power Tools, and the fix is available in the latest daily build
It's working now. Thanks!
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, IEnumerableb 0()
1 schemas, IEnumerable
1 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, IEnumerable
1 tableFilters, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>cDisplayClass0_0.<.ctor>b0() at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>cDisplayClass3_0`1.