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

Scaffold-DbContext with -ContextDir flag doesn't add namespace for models #17839

Closed
CamSoper opened this issue Sep 13, 2019 · 1 comment · Fixed by #18405
Closed

Scaffold-DbContext with -ContextDir flag doesn't add namespace for models #17839

CamSoper opened this issue Sep 13, 2019 · 1 comment · Fixed by #18405
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported good first issue This issue should be relatively straightforward to fix. type-bug
Milestone

Comments

@CamSoper
Copy link

CamSoper commented Sep 13, 2019

The database context generated by Scaffold-DbContext doesn't include any using directives pointing to the models that are generated when the DbContext is placed in a different folder using the -ContextDir flag.

Steps to reproduce

  1. Reverse engineer a database using the following command-line options:

    Scaffold-DbContext "Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=ContosoPets;Integrated Security=True;ConnectRetryCount=0" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -ContextDir Data -Context ContosoPetsContext
    
  2. Attempt to build.

  3. Note that the build fails because the the entity model classes can't be resolved in ContotoPetsContext.db.

Further technical details

EF Core version: 3.0 preview 9
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: NET Core 3.0
Operating system: Windows 1903
IDE: Visual Studio 2019 16.3.3

I'm MSFT-internal. Hit me up on Teams if you need repro help.

cc: @divega

@ErikEJ
Copy link
Contributor

ErikEJ commented Oct 16, 2019

This is implemented in the daily build of EF Core Power Tools @CamSoper

@bricelam bricelam added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed punted-for-3.1 labels Oct 16, 2019
@bricelam bricelam modified the milestones: Backlog, 3.1.0 Oct 16, 2019
bricelam pushed a commit that referenced this issue Oct 17, 2019
Summary of changes

- Add a new parameter to the WriteCode method of the ICSharpDbContextGenerator interface to pass the namespace of the models
- CSharpDbContextGenerator generates a using statement in the DbContext class if the models are in another namespace
- Add two test on CSharpDbContextGeneratorTest

Fixes #17839
@ajcvickers ajcvickers modified the milestones: 3.1.0, 3.1.0-preview2 Oct 24, 2019
@ajcvickers ajcvickers modified the milestones: 3.1.0-preview2, 3.1.0 Dec 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported good first issue This issue should be relatively straightforward to fix. type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants