Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC4 model property should be a list or an ICollection of another class
    primarykey
    data
    text
    <p>I'm making a type of test-generation application using Entity Framework code-first. I have a base class called <code>Question</code>, from which <code>MultipleChoiceQuestion</code>, <code>EssayQuestion</code>, and other question types descend. <code>MultipleChoiceQuestions</code> obviously have multiple answers from which the test taker must select. My question has to do with choosing the best way to store them in the question instance.</p> <p>I could declare the class with a List of Strings to hold the answers, like so:</p> <pre><code>public class MulitpleChoiceQuestion : Question { private List&lt;String&gt; Answers = new List&lt;String&gt;(); // other declarations, etc. } </code></pre> <p>Instead I could declare another class called <code>Answers</code>, and let my <code>Question</code> classes use a collection of Answers.</p> <pre><code>public class Answer { public int AnswerID { get; set; } public String AnswerText { get; set; } public virtual Question Question { get; set; } } </code></pre> <p>And then in my question subclasses (not just <code>MultipleChoiceQuestions</code>) </p> <pre><code>public class MulitpleChoiceQuestion : Question { public virtual ICollection&lt;Answer&gt; Answers { get; set; } // other declarations, etc. } </code></pre> <p>Is there a better way than either of these? If not, which of these is better, and why? I'm having a difficult time finding anything this detailed on the web, and most books don't go this deep either. Thanks in advance for any guidance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload