title: Entity Framework Nested Table Relation SelectMany
body: <p>My problem is the following query return zero records.But there are records in the database.</p>
  
  <p>My aim SubjectQuestion Select the table by Subjectid get that equal questionmodel.</p>
  
  <p>How can I do. Help you Thank you.</p>
  
  <p>[My Models]</p>
  
  <blockquote>
    <p><strong>SubjectQuestion</strong></p>
  </blockquote>
  
  <pre><code>public  class SubjectQuestion
  {
      public int Id { get; set; }
      public int SubjectId { get; set; }
      public int QuestionId { get; set; }
      public virtual List&lt;Question.Question&gt; Question { get; set; }
  }
  </code></pre>
  
  <p><strong>Question</strong></p>
  
  <pre><code>public class Question
  {
      public int Id { get; set; }
      public int QuestionNo { get; set; }
      public string Title { get; set; }
      public string Description { get; set; }
      public bool IsDeleted { get; set; }
      public QuestionModel ToModel()
     {
         return new QuestionModel(Id,QuestionNo,Title,Description,ChoiceId);
     }    
  }
  </code></pre>
  
  <p><strong>QuestionModel</strong></p>
  
  <pre><code>public class QuestionModel
  {
      public QuestionModel(int id, int questionNo, string title, string description,int choiceid)
      {
          Id = id;
          QuestionNo = questionNo;
          Title = title;
          Description = description;
          ChoiceId = choiceid;
      }
      public int Id { get; set; }
      public int QuestionNo { get; set; } 
      public string Title { get; set; }
      public string Description { get; set; }
      public bool IsDeleted { get; set; } 
  } 
  </code></pre>
  
  <p><strong>Entity Framework Query</strong> </p>
  
  <pre><code>List&lt;QuestionModel&gt; lst = _db.SubjectQuestions.Where(x =&gt; x.SubjectId == subjectId).ToList().SelectMany(r=&gt; r.Question.Select(y=&gt; y.ToModel()).ToList()).ToList();
  </code></pre>