Fix VS instructions for RP/EF (#7766)
* Fix VS instructions for RP/EF * Fix VS instructions for RP/EF * Fix VS instructions for RP/EFpull/7779/head
parent
0d35544256
commit
e9d7f30c4e
|
@ -147,24 +147,23 @@ The preceding commands:
|
|||
<a name="scaffold"></a>
|
||||
## Scaffold the Departments model
|
||||
|
||||
* Exit Visual Studio.
|
||||
* Open a command window in the project directory (The directory that contains the *Program.cs*, *Startup.cs*, and *.csproj* files).
|
||||
* Run the following command:
|
||||
# [Visual Studio](#tab/visual-studio)
|
||||
|
||||
Follow the instructions in [Scaffold the student model](xref:data/ef-rp/intro#scaffold-the-student-model) and use `Department` for the model class.
|
||||
|
||||
# [.NET Core CLI](#tab/netcore-cli)
|
||||
|
||||
Run the following command:
|
||||
|
||||
```console
|
||||
dotnet aspnet-codegenerator razorpage -m Department -dc SchoolContext -udl -outDir Pages\Departments --referenceScriptLibraries
|
||||
```
|
||||
|
||||
------
|
||||
|
||||
The preceding command scaffolds the `Department` model. Open the project in Visual Studio.
|
||||
|
||||
Build the project. The build generates errors like the following:
|
||||
|
||||
`1>Pages/Departments/Index.cshtml.cs(26,37,26,43): error CS1061: 'SchoolContext' does not
|
||||
contain a definition for 'Department' and no extension method 'Department' accepting a first
|
||||
argument of type 'SchoolContext' could be found (are you missing a using directive or
|
||||
an assembly reference?)`
|
||||
|
||||
Globally change `_context.Department` to `_context.Departments` (that is, add an "s" to `Department`). 7 occurrences are found and updated.
|
||||
Build the project.
|
||||
|
||||
### Update the Departments Index page
|
||||
|
||||
|
|
|
@ -64,15 +64,20 @@ To display the name of the assigned department in a list of courses:
|
|||
<a name="scaffold"></a>
|
||||
### Scaffold the Course model
|
||||
|
||||
* Exit Visual Studio.
|
||||
* Open a command window in the project directory (The directory that contains the *Program.cs*, *Startup.cs*, and *.csproj* files).
|
||||
* Run the following command:
|
||||
# [Visual Studio](#tab/visual-studio)
|
||||
|
||||
Follow the instructions in [Scaffold the student model](xref:data/ef-rp/intro#scaffold-the-student-model) and use `Course` for the model class.
|
||||
|
||||
# [.NET Core CLI](#tab/netcore-cli)
|
||||
|
||||
Run the following command:
|
||||
|
||||
```console
|
||||
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design --version 2.1.0
|
||||
dotnet aspnet-codegenerator razorpage -m Course -dc SchoolContext -udl -outDir Pages\Courses --referenceScriptLibraries
|
||||
```
|
||||
|
||||
------
|
||||
|
||||
The preceding command scaffolds the `Course` model. Open the project in Visual Studio.
|
||||
|
||||
Open *Pages/Courses/Index.cshtml.cs* and examine the `OnGetAsync` method. The scaffolding engine specified eager loading for the `Department` navigation property. The `Include` method specifies eager loading.
|
||||
|
@ -145,20 +150,21 @@ In the *SchoolViewModels* folder, create *InstructorIndexData.cs* with the follo
|
|||
|
||||
### Scaffold the Instructor model
|
||||
|
||||
* Exit Visual Studio.
|
||||
* Open a command window in the project directory (The directory that contains the *Program.cs*, *Startup.cs*, and *.csproj* files).
|
||||
* Run the following command:
|
||||
# [Visual Studio](#tab/visual-studio)
|
||||
|
||||
Follow the instructions in [Scaffold the student model](xref:data/ef-rp/intro#scaffold-the-student-model) and use `Instructor` for the model class.
|
||||
|
||||
# [.NET Core CLI](#tab/netcore-cli)
|
||||
|
||||
Run the following command:
|
||||
|
||||
```console
|
||||
dotnet aspnet-codegenerator razorpage -m Instructor -dc SchoolContext -udl -outDir Pages\Instructors --referenceScriptLibraries
|
||||
```
|
||||
|
||||
The preceding command scaffolds the `Instructor` model. Open the project in Visual Studio.
|
||||
|
||||
Build the project. The build generates errors.
|
||||
|
||||
Globally change `_context.Instructor` to `_context.Instructors` (that is, add an "s" to `Instructor`). 7 occurrences are found and updated.
|
||||
------
|
||||
|
||||
The preceding command scaffolds the `Instructor` model.
|
||||
Run the app and navigate to the instructors page.
|
||||
|
||||
Replace *Pages/Instructors/Index.cshtml.cs* with the following code:
|
||||
|
|
Loading…
Reference in New Issue