title: How can I use LINQ to populate a collection inside a collection?
body: <p>I have the following LINQ code that I created:</p>
  
  <pre><code> QuestionDetail questions = _questionsRepository
                  .GetAll()
                  .Include(q =&gt; q.Answers)
                  .Select(m =&gt; new QuestionDetail
                  {
                      QuestionId = m.QuestionId,
                      Text = m.Text,
                      Answers // &lt;&lt; I am not sure how to populate this
                              // &lt;&lt; I need to have a new collection 
                              // &lt;&lt; created from a subset of the m.Answers
                  })
                  .FirstOrDefault();
  </code></pre>
  
  <p>My problem is that I am not sure how to populate the <code>ICollection&lt;AnswerDetail&gt; Answers</code> collection that is part of the QuestionDetail. What I need is to somehow select from the m.Answers and use this to populate the AnswerDetail collection. I know I cannot use new AnswerDetail as Answers is a collection. </p>
  
  <p>Can anyone help and tell me how I could do this. </p>
  
  <p>Below I have listed some of the classes for this. To make it simpler I removed some fields from the Question and Answer classes.</p>
  
  <pre><code>public class QuestionDetail
  {
      public int QuestionId { get; set; }
      public string Text { get; set; }
      public virtual ICollection&lt;AnswerDetail&gt; Answers { get; set; }
  }
  
  public class AnswerDetail
  {
      public int AnswerId { get; set; }
      public string Text { get; set; }
  }
  
  public class Answer
  {
      public int AnswerId { get; set; }
      public int QuestionId { get; set; }
      public Nullable&lt;bool&gt; Correct { get; set; }
      public Nullable&lt;bool&gt; Response { get; set; }
      public string Text { get; set; }
      public virtual Question Question { get; set; }
  }
  
  public class Question
  {
      public Question()
      {
          this.Answers = new List&lt;Answer&gt;();
      }
      public int QuestionId { get; set; }
      public string Text { get; set; }
      public string Image { get; set; }
      public virtual ICollection&lt;Answer&gt; Answers { get; set; }
  }
  </code></pre>