How do I model a 3-table database in a ASP.NET web app using Razor Pages?

asp.net entity-framework-core multiple-tables razor-pages sql-server

Question

Creating my first web app. Using ASP.NET and Razor Pages+. Developing it in VS 2017.

(Note: Similar to unanswered S.O. question ASP.NET Core : Generate Razor Pages for all models)

+In ASP.NET Core tutorials [https://docs.microsoft.com/en-us/aspnet/core/tutorials/?view=aspnetcore-2.1] it says this: "Razor Pages is the recommended approach to create a new Web UI app with ASP.NET Core 2.0."

First thing I did was create my database using SSMS:

enter image description here

Then, I created a ASP.NET Core Web Application

enter image description here

Then, I created a model from the existing database (Used only the Reverse engineer your model step of Getting Started with EF Core on ASP.NET Core with an Existing Database

enter image description here

Then, I used the Scaffold the movie model step of Add a model to a Razor Pages app in ASP.NET Core

enter image description here

The scaffolding step requires that you choose one class from the Models folder and produces generically-named CRUD pages in (my case) the Pages\keyw_status folder.

If I scaffold the 2nd and 3rd classes from my model, the generically-named CRUD pages in the Pages\keyw_status folder will be overwritten. Last model class scaffolded wins, right?

How do I scaffold a 3-table model using Razor Pages?

1
1
9/29/2018 2:37:58 PM

Accepted Answer

You can specify the folder for the scaffolded pages using the -outDir option to ensure that the CRUD pages for each entity are generated in different folder. Usually, people pick the name of the entity for the folder, because that becomes your URL.

The following command will scaffold CRUD pages for the DateTable entity, and place them in Pages\DataTable.

dotnet aspnet-codegenerator razorpage -m DateTable -dc keyw_statusContext -udl -outDir Pages\DateTable
1
9/29/2018 7:59:20 PM


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