Aspnetcore.docs: Details not returning Courses and Grades

Created on 2 Feb 2019  Â·  7Comments  Â·  Source: dotnet/AspNetCore.Docs

In the "add related data" section, how are the enrollments connected to the students? I have students that show up in the index, but the details page doesn't show the courses or grades. When I went through the code, I don't know how the student IDs are connecting to the enrollments with the hard coded ID numbers.


Document Details

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

P3 Source - Docs.ms

Most helpful comment

@roberthleone,
Maybe this will help you and others that encounter this issue. For the Student entity the ID will be generated automatically in the database. If you for example deleted a student during testing, its ID will now longer exists in the Student table. When the Enrollments should be added, later in the tutorial, it will go wrong. Because the example couples the Student ID hard coded, starting with 1. In other words you have to Reset the identity seed after deleting records in SQL Server.
So, first delete all data in the database via SQL Server Object Explorer. Then open a new Query and past the following code:

DBCC CHECKIDENT ('[Student]', RESEED, 0);
GO

Run this query and the identity seed will be reset.
Clean your solution, run it again and you will be set.

All 7 comments

The Include and ThenInclude methods cause the context to load the Student.Enrollments navigation property, and within each enrollment the Enrollment.Course navigation property. These methods are examined in detail in the reading-related data tutorial.

There are no hard coded ID numbers.

Try the sample download. The code does work.

@Rick-Anderson,
Try walking through the code up to around that point and test it for yourself. Telling me to download the finished product and saying that it works isn't really a welcoming gesture. Do better. My issue isn't resolved by you saying it's fine. Take some time to look into it.

In the "add related data" section, how are the enrollments connected to the students?

The Include and ThenInclude methods cause the context to load the Student.Enrollments navigation property, and within each enrollment the Enrollment.Course navigation property. These methods are examined in detail in the reading-related data tutorial.

I recommend you keep going through the tutorial and see if you can figure it out. These methods are examined in detail in the reading-related data tutorial. I recently tested the entire tutorial and everything worked.

@roberthleone,
Maybe this will help you and others that encounter this issue. For the Student entity the ID will be generated automatically in the database. If you for example deleted a student during testing, its ID will now longer exists in the Student table. When the Enrollments should be added, later in the tutorial, it will go wrong. Because the example couples the Student ID hard coded, starting with 1. In other words you have to Reset the identity seed after deleting records in SQL Server.
So, first delete all data in the database via SQL Server Object Explorer. Then open a new Query and past the following code:

DBCC CHECKIDENT ('[Student]', RESEED, 0);
GO

Run this query and the identity seed will be reset.
Clean your solution, run it again and you will be set.

Thanks for contacting us. We believe that the question you've raised have been answered. If you still feel a need to continue the discussion, feel free to reopen it and add your comments.

As the OP mentioned, just going through the tutorial as written causes no courses or grades to be displayed when you get to the section where they should be because the Enrollment table is not populated. Sw1ma has indicated the cause and provided one work around. Another workaround is to delete the entire DB and let it get recreated from the start.

IMO, the tutorial needs work in this area. A couple options include: 1) the code in the initializer shouldn't have hard coded student ID values for the enrollment entities, 2) the student should be instructed how to reset the identity seed manually or 3) the initializer should reset the identity seed.

Was this page helpful?
0 / 5 - 0 ratings