title: Entity Command Execution Exception
body: <p>I get Entity Command Execution Exception while compiling. Same line of code works fine somewhere else, but in place I need it returns this exception. </p>
  
  <pre><code>//Working fine here!
  Questionnaire questionnaireeeee = context.Set&lt;Questionnaire&gt;().Include(q =&gt; q.QuestionnaireQuestions.Single(q =&gt; q.ID == 1);
  //need to see who is logged in, administrator or professor
   string userId = User.Identity.GetUserId();
  //...
  if(User.IsInRole("Administrator"))
  {
      //grouping subject instances by same semester
      var subjectInstancesBySemester = from subjectInstances in context.SubjectInstances group subjectInstances by subjectInstances.Semester;
      foreach (var subjectInstancesGroup in subjectInstancesBySemester)
      {
           // getting questionnaire related to this semester
           if(subjectInstancesGroup.Key.QuestionnaireID != null)
           {
          //Exception is here!
               Questionnaire questionnaire = context.Set&lt;Questionnaire&gt;().Include(q =&gt; q.QuestionnaireQuestions).Single(q =&gt; q.ID == (int) subjectInstancesGroup.Key.QuestionnaireID);
               //...
           }
      }
  }
  </code></pre>
  
  <p>And I checked with breakpoint, subjectInstancesGroup.Key.QuestionnaireID has value 1, and there is row in table Questionnaire with ID of 1. Where is the problem?</p>