Skip to content

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

Open
@tejasvih

Description

@tejasvih

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions