Example

Let's say the number of answers of multiple choice questions varies. One question can have only 2 choices while another can have 10 choices.

How can I save these multiple choice questions in my MSSQL database? Is the following model viable?

public class MultipleChoiceQuestion
{
    [Key]
    public Guid Id { get; set; }

    [Required]
    public string Question { get; set; }

    // Suppose I can have 2-10 answers
    [Required]
    public List<string> Answers { get; set; }
}

Question

  • Can we store a list of objects with various length in MSSQL database with code-first migration enabled in ASP.NET?
  • If it is not applicable, what is the best solution to deal with such problems?

Related posts

Recent Viewed