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

Can't get CRUD scaffolding to work after running Reverse Engineer from EF Core Power Tools, throws breaking error #2625

Open
Catfang opened this issue Jan 22, 2024 · 2 comments

Comments

@Catfang
Copy link

Catfang commented Jan 22, 2024

NOTE: I've already requested help from Erik, the author of EF Core Power Tools. He closed my ticket (with no additional help) and sent me here.

I am trying something that appears very straight-forward, but am getting stuck. Maybe I'm not using the correct process?

High-level description: I have an existing DB with two tables and a single SP. I can reverse engineer the DB using EFPowerTools and operation completes without issue. However, if I then try to scaffold a new page based on one of the created Models, I get an error: "Error - There was an error running the selected code generator: 'Could not get the reflection type for DbContext : EFPowerToolsDemo.Data.DemoDbContext' ". I'm not sure how to proceed. Full details are below.

Provide steps to reproduce a bug

  • Created new project using "ASP.NET Core Web App (Razor Pages) template. Using .Net 8.0 (LTS) with no authentication type. Built project to verify code. Added "Models" and "Data" folders to root project.
  • Right-clicked on project name, EF Core Power Tools => Reverse Engineer. Choose the DB and EF Core version of 8.0. Picked the two tables and the SP. Set "EntityTypes path" to Models. Checked "Use DataAnnotation attributes to configure the model". Under Advanced... added Data folder to DbContext path. Click okay, let it run, then built the project to verify all the new code is functional.
  • Add 'NewPage' folder under Pages. Right-click on the new folder and Add => New Scaffolding Item... and then pick the Razor Pages using Entity Framwork (CRUD) option. Set Model class to generated model. Set DbContext class to generated context. Hit "add" and code creation starts, but error is thrown during process that ends the operation.
  • Error - There was an error running the selected code generator: 'Could not get the reflection type for DbContext : EFPowerToolsDemo.Data.DemoDbContext'

Provide technical details

EF Core Power Tools version: 2.6.72

Exact Visual Studio version: Microsoft Visual Studio Professional 2022 (64-bit) - Current, Version 17.8.5

Database engine: SQL Server Enterprise (GA)

EF Core version in use: EF Core 8

I tried this from scratch twice to make sure I didn't miss anything.

@ajcvickers
Copy link
Member

Add 'NewPage' folder under Pages. Right-click on the new folder and Add => New Scaffolding Item... and then pick the Razor Pages using Entity Framwork (CRUD) option. Set Model class to generated model. Set DbContext class to generated context.

Moving to the ASP.NET scaffolding repo.

@ajcvickers ajcvickers transferred this issue from dotnet/efcore Jan 23, 2024
@Catfang
Copy link
Author

Catfang commented Jan 23, 2024

I thought it might be due to an issue with the primary keys in the two tables that I'm accessing, but after some testing this morning it appears that the keys are not the issue.

FWIW, I get a slightly different error if I try the same scaffolding after running Reverse Engineer but without including the stored procedure: There was an error running the selected code generator: 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`[EFPowerToolsDemo.Demo.DemoDbContext]' while attempting to activate 'EFPowerToolsDemo.Data.DemoDbContext'.'

@Catfang Catfang changed the title Can't get CRUD scaffolding to work after running Reverse Engineer from EF Core Power Tools, get reflection error Can't get CRUD scaffolding to work after running Reverse Engineer from EF Core Power Tools, throws breaking error Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants