I am writing an ASP.Net Core MVC with EF application based on the Contoso University series of tutorials: https://learn.microsoft.com/en-us/aspnet/core/data/ef-mvc/intro?view=aspnetcore-2.1
In the Create a complex data model tutorial (ASP.NET Core MVC with EF Core - Data Model - 5 of 10) there is an illustration of the data model implemented.
In the 7th tutorial (ASP.NET Core MVC with EF Core - Update Related Data - 7 of 10) Tom Dykstra and Rick Anderson demonstrate how to edit most of the properties in the data model but not how to edit the payload ("Grade") of the "Enrollment" class/table which joins the "Student" and "Course" classes/tables.
What is the best way to change or assign a grade? How to you change the "payload" of the Enrollment class? I tried adding an EnrollmentsController and associated CRUD views but I get:
An unhandled exception occurred while processing the request.
SqlException: The UPDATE statement conflicted with the FOREIGN KEY
constraint "FK_Enrollment_Course_CourseID". The conflict occurred in
database "ContosoUniversity3", table "dbo.Course", column 'CourseID'.
when trying to edit the grade.
I asked this question on the tutorial itself and Rick Anderson suggested I ask the question here.
Before asking, I searched for the answer and my situation is similar to the one described in Mapping many to many relationship or in Updating in a many-to-many relationship but I need an answer using MVC and asp.net core.
Sql error on update : The UPDATE statement conflicted with the FOREIGN KEY constraint helps me understand the problem but not how to solve it in the Contoso University context.
Thanks.