efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Wrong model-namespace using in generated context

Open SchroeerM opened this issue 4 years ago • 1 comments

Hello,

if I try to scaffold an empty database to control it later by ef-versioning the generated context contains an using for the models-namespace. If the database is empty this namespace is empty as well and the compilation throws an error.

Steps to reproduce:

  1. create an empty database
  2. use "dotnet ef database scaffold" in an project
  3. try to compile the generated code.

Ive fixed this on my site but an general fix should prevent the first error-message which appears directly after executing the scaffold command.

Thanks, Michael

SchroeerM avatar Aug 10 '21 07:08 SchroeerM

As far as I can tell, you need to meet both of the following conditions to hit this.

  1. Have a database with no views or tables
  2. Specify a --context-namespace that's different from the entity types' --namespace

If this isn't the case, can you share more details?

bricelam avatar Aug 04 '22 19:08 bricelam

Note from triage: this very much a corner case. With the introduction of templates in EF7, this can be handled by editing the template if desired.

ajcvickers avatar Aug 11 '22 13:08 ajcvickers