question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scaffolding wants to use a different database provider to my project

See original GitHub issue

Ask a question

I am in the process of building a Asp.Net Core website with Razor pages, however whenever I attempt to use any of the scaffolding options that require a database context, one of two things happen.

Either A, the scaffolding process automatically installs ‘Microsoft.EntityFrameworkCore.SqlServer’ version 5.0.8, and downgrades ‘Microsoft.EntityFrameworkCore.Tools’ to version 5.0.8. Or B, it gives the following error message:

There was an error running the selected code generator:
'To scaffold, install the following Entity Framework core packages and try again:
Microsoft.EntityFrameworkCore.SqlServer.'

I have checked all of the files in my project and have found no mention of MS SQL Server anywhere. In fact the only references I have found to any database providers is in ‘Startup.cs’ and in the list of required packages. For reference, here is the code I use to add the database context under services.

services.AddDbContext<ApplicationDbContext>(options => {
                options.UseMySql(Configuration.GetConnectionString("DefaultConnection"),
                    ServerVersion.AutoDetect(Configuration.GetConnectionString("DefaultConnection")));
                options.UseLazyLoadingProxies(false);
            }) ;

Is there anywhere else I need to specify the database provider besides ‘ConfigureServices’ in ‘startup.cs’ in order for scaffolding to work, or is there something else I am missing that is causing scaffolding to use the incorrect database provider?

Provider and version information

EF Core version: 5.0.10 Database provider: Pomelo.EntityFrameworkCore.MySql Target framework: NET 5.0 Operating system: Windows 10 IDE: Visual Studio 2019 16.11.2

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
David-FGCScommented, Nov 9, 2021

Very well. Thank you for your time.

0reactions
Rick-Andersoncommented, Nov 9, 2021

I am sorry if I am misunderstanding something here, but I thought one of the benefits of using Entity Framework was that the underlying database provider was abstracted away?

Where did MS publish that?

See EF O/RM considerations While EF Core is good at abstracting many programming details, there are some …

This is not an EF repo, this is the scaffolding repo. Scaffolding MySQL was never planned.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Scaffolding (Reverse Engineering) - EF Core
Reverse engineering a model from an existing database using Entity Framework Core.
Read more >
Scaffold-DbContext to different output folder
As the top answer indicates, if you want a different folder within that project, you can just use the -OutputDir option.
Read more >
Stop adding connection string into code when scaffolding
When I run the command: dotnet ef dbcontext scaffold " " Microsoft.EntityFrameworkCore.SqlServer -o "Data" -c "ApiDbContext" -f It generates ...
Read more >
Scaffold Existing Database - Entity Framework Core - YouTube
Scaffold Existing Database - Entity Framework Core | Trevoir ... a database context file from an existing database using EF Core commands.
Read more >
Create an EF Core Model from Database First (Scaffold DB ...
In this video I'll show you how to use the Scaffold DB Context ... How to use Entity Framework Core Database -First in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found