I have a very specific problem, which I would like to ask here for help. I'm using .NET Core 2.1.1 with EF Core 2.1.1. I'm using the code first approach and currently am designing a domain model for my application.
So I have the following requirement: I have a TrainingItem
class, which contains basic information about training. TrainingItem
also contains a list of attendees, so I am using the many-to-many relationship between TrainingItem
and TrainingEmployee
. The problem is that I have a requirement that TrainingItem
should contain a list of employees that are waiting for this training, so I came up with the following approach:
public class TrainingItem
{
// ... properties for Training
public virtual ICollection<TrainingEmployeeTrainingItem> Attendees {get;set;} = new List<TrainingEmployeeTrainingItem>();
public virtual ICollection<TrainingEmployeeTrainingItem> WaitingList {get;set;} = new List<TrainingEmployeeTrainingItem>();
}
public class TrainingEmployee
{
// ... properties for Employee
public virtual ICollection<TrainingEmployeeTrainingItem> TrainingEmployeeTrainingItems {get;set;} = new List<TrainingEmployeeTrainingItem>();
}
public class TrainingEmployeeTrainingItem
{
public int TrainingEmployeeId {get;set;}
public virtual TrainingEmployee TrainingEmployee {get;set;}
public int TrainingItemId {get;set;}
public virtual TrainingItem TrainingItem {get;set;}
}
// this is my model creating method in db context
protected override void OnModelCreating(ModelBuilder builder)
{
// many-to-many
builder.Entity<TrainingEmployeeTrainingItem>()
.HasKey(x => new { x.TrainingEmployeeId, x.TrainingItemId });
}
So as you can see the first list of attendees can be mapped with a workaround that is currently in EF Core used for mapping many-to-many relationships.
But the question is, how can I map WaitingList?