TrackableEntities / EntityFrameworkCore.Scaffolding.Handlebars

Scaffold EF Core models using Handlebars templates.
MIT License
208 stars 53 forks source link

[Bug] Model Imports wrongly generated when EnableSchemaFolders = true when contextNamespace and modelNamespace are same or blank #214

Open tejasvih opened 1 year ago

tejasvih commented 1 year ago

Describe the bug Imports are wrongly generated (e.g. using masters = .masters) in context file when EnableSchemaFolders = true in options but either namespace is not provided or its same for context and model.

Expected behavior It should generate namespace as using <schema> = <modelNamespace>.<schema> or using <modelNamespace>.<schema>

To Reproduce Using PostgreSQL with

Scaffold-DbContext Name=<connection string> Npgsql.EntityFrameworkCore.PostgreSQL -Namespace SomeAPI.DbModels -ContextNamespace SomeAPI.DbModels -o DbModels

or

Scaffold-DbContext Name=<connection string> Npgsql.EntityFrameworkCore.PostgreSQL -o DbModels

Make My Life Easier This seems to be happening due to this condition , which is not assigning value to _modelNamespace when both namespace are same File: HbsCSharpDbContextGenerator.cs Method: WriteCode(..)

if (!string.IsNullOrEmpty(modelNamespace) && string.CompareOrdinal(contextNamespace, modelNamespace) != 0)
                _modelNamespace = modelNamespace;