Update read-related-data.md (#7608)

pull/7613/head
Rick Anderson 2018-07-13 13:38:32 -06:00 committed by GitHub
parent 995a84e6e7
commit ffccdf3adb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 9 deletions

View File

@ -69,20 +69,12 @@ To display the name of the assigned department in a list of courses:
* 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.
Build the project. The build generates errors like the following:
`1>Pages/Courses/Index.cshtml.cs(26,37,26,43): error CS1061: 'SchoolContext' does not
contain a definition for 'Course' and no extension method 'Course' accepting a first
argument of type 'SchoolContext' could be found (are you missing a using directive or
an assembly reference?)`
Globally change `_context.Course` to `_context.Courses` (that is, add an "s" to `Course`). 7 occurrences are found and updated.
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.
Run the app and select the **Courses** link. The department column displays the `DepartmentID`, which isn't useful.