Skip to content

Add Instructor-Course relationship#21

Merged
JoeProgrammer88 merged 1 commit intomainfrom
AddCourseInstructor
Oct 10, 2025
Merged

Add Instructor-Course relationship#21
JoeProgrammer88 merged 1 commit intomainfrom
AddCourseInstructor

Conversation

@JoeProgrammer88
Copy link
Copy Markdown
Member

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

  • Added a one-to-many relationship between Instructor and Course, where each instructor can have multiple courses, and each course requires a CourseInstructor. Cascade deletes are restricted to prevent accidental removal of courses when an instructor is deleted. (SpeakingInBitsWeb/Data/ApplicationDbContext.cs)

Database Migrations

  • Created a migration (AddCourseInstructor) that adds a CourseInstructorId column to the Courses table and a Discriminator column to the AspNetUsers table, sets up the necessary foreign key constraint, and ensures referential integrity with restricted deletes. (SpeakingInBitsWeb/Data/Migrations/20251010170338_AddCourseInstructor.cs)
  • Updated the migration designer file to reflect the new model structure, including the instructor-course relationship and the discriminator for user types. (SpeakingInBitsWeb/Data/Migrations/20251010170338_AddCourseInstructor.Designer.cs)

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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@JoeProgrammer88 JoeProgrammer88 merged commit a04cca0 into main Oct 10, 2025
1 check passed
@JoeProgrammer88 JoeProgrammer88 deleted the AddCourseInstructor branch October 10, 2025 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants