I have a project to create an asp.net mvc site to generate a quiz.
Here is the specification:
- For each user visiting the site, she/he gets a quiz.
- Each quiz contains some multiple-choice problems.
- Each problem contains a question and 5 mutually-exclusive choices.
The simplest model I can think of is as follows:
public class Problem
{
public int ProblemId { get; set; }
public string Question { get; set; }
public string A { get; set; }
public string B { get; set; }
public string C { get; set; }
public string D { get; set; }
public string E { get; set; }
}
I am not sure it is good.
Could you give me a suggestion for a better design?
Simple and intuitive designs are always the best and since they are really simple, we start doubting ourselves ;-). You are doing good except you can also store the correct answer with the Problem itself. Then it is no longer just a Problem. So now it is ProblemAndAnswer or QuizItem.
So this is all OK to store in a single table as multiple columns. But you also need to understand what it means. This means that you are making an assumption that a question is always going to have 5 choices. If you going to have less than 5 then it is ok as you can store nulls. But what if you are going to have more? This is when the single table model starts falling apart. You would now start thinking that a Question really can have 1 or more choices and would want to split into parent child tables….now you have made a well-informed decision 😉