I am trying to find a way to build a model in Entity Framework to represent LearningJourneys, Courses and Lessons, where each course can have multiple Courses and lessons within it. However i also want to make it so lessons and courses can be used in multiple LearningJourneys.
So far my idea is to:
a) Make an entity for the LearningJourney to act as a Root for a tree structure.
public class LearningJourney
{
public Guid Id { get; set; }
}
b) Make a LearningItem abstract class for Course and Lesson to store all common logic, and make inheriting Lesson and Course classes
public abstract class LearningItem
{
public Guid Id { get; set; }
public string Description { get; set; }
public string Title { get; set; }
public abstract bool CanHaveChildren { get;}
}
public abstract class Course : LearningItem
{
public override bool CanHaveChildren => true;
}
public abstract class Lesson : LearningItem
{
public override bool CanHaveChildren => false;
}
c) Make a separate class to store relationships LearningJourneyLearningItem
public class LearningJourneyLearningItem
{
public Guid Id { get; set; }
public LearningJourney LearningJourney { get; set; }
public LearningItem LearningItem { get; set; }
public Guid? ParentNodeId { get; set; }
public LearningItem? ParentNode { get; set; }
public int OrderInParent { get; set; }
public int Depth { get; set; }
}
However I cannot figure out how to correctly set it up in the OnModelCreating.. or if it is at all a viable approach.
can someone suggest how to set this up?