-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Description
Issue
When I reverse from an existing database EF handles namespaces incorrectly, and does not honor the project default namespace.
Example
I have a project I created with the name "MyProjectSite". (This is a Core on 4.6 web application)
In this project I have set the default namespace to "MyProject".
In Package Manager, if I scaffold with -o ProjectSection/Models -context SectionContext I will get the context:
MyProjectSite.ProjectSection.Models.SectionContext
The correct name should be:
MyProject.ProjectSection.Models.SectionContext
All of my entity classes are also in the wrong namespace.
As an experiment I renamed the project "MyProject" from within Visual Studio (right click->rename on project) to see if the project hierarchy in solution explorer was where the namespace came from. The results were the same.
I also tried to see if I could apply a full namespace in the command using -context MyProject.ProjectSection.Models.SectionContext. This throws an incorrect naming error.
Proposed
-
Bug - EF should use the default namespace specified in the project when scaffolding.
-
Feature - EF should allow better control over namespaces. Two approaches are
a) Allow the -context switch to accept a fully qualified name (and make things relative to the context)
b) Add a -namespace switch to the command. (preferred)
Discussion
Having better control over namespaces is very valuable, and -namespace is a good option. For example, when I am in early design I do a lot of iterative reversing. I can put all of my reversed files in a single directory with the -output switch (e.g., /Models/Generated), but then I have "Generated" in the namespace for every class. Better would be -output /Models/Generated -namespace /Models. (or -namespace .Models, or -namespace MyProject.Models.)