AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

Doesn't mention Database First approach

Open ChuckBevitt opened this issue 6 years ago • 1 comments

This article only explains Razor with EntityFrameworkCore using the Code First approach which assumes that you're creating a new database or tables for the application. It ignores the Database First approach where you're creating an application for an existing database. While EntityFrameworkCore doesn't implement all of the wizards that .Net EntityFramework does, it is possible to generate the data models from an existing database. See the article at: https://www.entityframeworktutorial.net/efcore/create-model-for-existing-database-in-ef-core.aspx. Substitute this for the portion of the article that manually creates the data classes (to follow this example you'll have to manually create the SQL Server database / tables instead), then just continue on with the scaffolding. Of course, change the database connect string in the appsettings.json file to point to your database (to match this example, the database name has to be 'SchoolContext'). Works fine and avoids having manually create a bunch of matching data models for a preexisting, possible complex, database.


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

ChuckBevitt avatar Feb 07 '20 00:02 ChuckBevitt

See also the EF Core documentation: https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell#scaffold-dbcontext and https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet#dotnet-ef-dbcontext-scaffold

Rick-Anderson avatar Feb 10 '20 19:02 Rick-Anderson