Add Instructor-Course relationship#21
Merged
JoeProgrammer88 merged 1 commit intomainfrom Oct 10, 2025
Merged
Conversation
Introduced a one-to-many relationship between `Instructor` and `Course` with `DeleteBehavior.Restrict` to prevent cascade deletes. Refactored `ApplicationUser` into `CustomUsers.cs` and added an `Instructor` subclass with `OfficeHours` and a navigation property for `Courses`. Updated `Course` to include a required `CourseInstructor` property. Added migrations to update the database schema: - Added `CourseInstructorId` to `Courses` and `Discriminator` to `AspNetUsers` for TPH inheritance. - Added `OfficeHours` column to `AspNetUsers` with a max length of 200. Updated `ApplicationDbContextModelSnapshot` and migration designer files to reflect these changes.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a one-to-many relationship between instructors and courses, where each instructor can teach multiple courses and each course must have an assigned instructor. The changes include creating an Instructor entity that inherits from ApplicationUser, adding the relationship configuration, and generating the necessary database migrations.
Key changes:
- Refactored ApplicationUser into a base class with an Instructor subclass that includes course relationships
- Added required CourseInstructor navigation property to Course entity with restricted delete behavior
- Generated three database migrations to support the new relationship and entity structure
Reviewed Changes
Copilot reviewed 8 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| SpeakingInBitsWeb/Models/CustomUsers.cs | New file containing ApplicationUser base class and Instructor subclass with course navigation property |
| SpeakingInBitsWeb/Models/Course.cs | Added required CourseInstructor navigation property |
| SpeakingInBitsWeb/Models/ApplicationUser.cs | Removed original ApplicationUser class (moved to CustomUsers.cs) |
| SpeakingInBitsWeb/Data/ApplicationDbContext.cs | Added Entity Framework configuration for instructor-course relationship with restricted deletes |
| SpeakingInBitsWeb/Data/Migrations/ApplicationDbContextModelSnapshot.cs | Updated model snapshot to reflect new entity structure and relationships |
| SpeakingInBitsWeb/Data/Migrations/20251010170338_AddCourseInstructor.cs | Migration adding CourseInstructorId column and Discriminator for table-per-hierarchy inheritance |
| SpeakingInBitsWeb/Data/Migrations/20251010170842_InstructorOfficeHours.cs | Migration adding OfficeHours column to AspNetUsers table |
| SpeakingInBitsWeb/Data/Migrations/20251010171129_OfficeHoursLength.cs | Migration updating OfficeHours column length constraint |
Files not reviewed (3)
- SpeakingInBitsWeb/Data/Migrations/20251010170338_AddCourseInstructor.Designer.cs: Language not supported
- SpeakingInBitsWeb/Data/Migrations/20251010170842_InstructorOfficeHours.Designer.cs: Language not supported
- SpeakingInBitsWeb/Data/Migrations/20251010171129_OfficeHoursLength.Designer.cs: Language not supported
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Work needed for #6
This pull request introduces a new relationship between instructors and courses in the application, ensuring that each course is associated with an instructor and preventing accidental deletion of instructors that would cascade to their courses. The changes include updates to the data model, Entity Framework configuration, and database migration files.
Data Model and Entity Relationships
InstructorandCourse, where each instructor can have multiple courses, and each course requires aCourseInstructor. Cascade deletes are restricted to prevent accidental removal of courses when an instructor is deleted. (SpeakingInBitsWeb/Data/ApplicationDbContext.cs)Database Migrations
AddCourseInstructor) that adds aCourseInstructorIdcolumn to theCoursestable and aDiscriminatorcolumn to theAspNetUserstable, sets up the necessary foreign key constraint, and ensures referential integrity with restricted deletes. (SpeakingInBitsWeb/Data/Migrations/20251010170338_AddCourseInstructor.cs)SpeakingInBitsWeb/Data/Migrations/20251010170338_AddCourseInstructor.Designer.cs)