I have a question about inheritance strategies with the code first approach of entity framework.
Currently i have to implement a variety of question tables to our database.
This is my current QuestionBase class, which has all the properties every type of question needs.
public class QuestionBase
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int QuestionId { get; set; }
[Required]
public QuestionType QuestionType { get; set; }
public string ShortDescription { get; set; } = string.Empty;
[Required(AllowEmptyStrings = true)]
public string QuestionText { get; set; } = string.Empty;
[Required]
public double MaxScore { get; set; }
public bool MixedAnswers { get; set; } = true;
}
At the moment i have only two different types of questions: SingleChoice and MultipleChoice. The only difference between those types is the navigation property as shown here:
public class SingleChoiceQuestion : QuestionBase
{
public virtual List<SingleChoiceAnswer> Answers { get; set; }
}
public class MultipleChoiceQuestion : QuestionBase
{
public virtual List<MultipleChoiceAnswer> Answers { get; set; }
}
My current approach results in table per hierarchie inheritance. As soon as i add a new question type, which contains additional properties, the QuestionBase table will be expanded by additional columns. This is not what i want.
Table per type inheritance is not an option, because i do not know how many different question types will be added in future. I am afraid, the amount of different question types could result in performance issues.
Table per concrete class inheritance is also not what i want.
I also thought about working without inheritance, but with foreign keys and navigation properties instead. But then i realised that at least my first two questions types would result in additional tables with a foreign key for the QuestionBase table only, because they have no additional properties. This does not seem right.
May be there is any other approach i could try?