Does EF Core 3.1 support DB First approach?

asp.net-core asp.net-mvc entity-framework entity-framework-core porting

Question

We are porting an ASP.NET MVC 4.x application to ASP.NET Core 3.1. The current application is using EF 6.x DB first approach. As a part of this migration we are going to use EF Core 3.1 as an alternative to the current EF 6.x. So the question is:

Does EF Core 3.1 support DB First approach?

If not, what are the options? Are we left with only code first approach?

Appreciate your helps.

1
2
1/23/2020 9:56:36 PM

Popular Answer

Yes. It supports DB First Approach since .NET Core 1.0 until now. You need to download 4 from nugets

1) EntityFrameworkCore

2) EntityFrameworkCore.Design

3) EntityFrameworkCore.Tools

4) EntityFrameworkCore.SqlServer

Open Tools > NuGet Package Manager > Package Manager Console. And enter this below in console.

Scaffold-DbContext "Server=yourserveraddress;Database=yourdatabase;user id=youruser;password=yourpassword;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Context "YourOwnContext"

Saw your comment about "Scaffold-DbContext only creates a Code First model". No, Scaffold-DbContext is Database-First approach.

"Creating entity & context classes for an existing database is called Database-First approach."

4
1/20/2020 1:19:52 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow