title: MVC 3 Entity Framework Empty Result Set
body: <p>I am working on an application in which it returns an excel report with each employee having multiple roles and their expected and actual hours for each role. For instance, I may be listed as a developer for one and a BA for another column!. The query it is using is returning an empty result set. </p>
  
  <pre><code>    public ActionResult ExpectedVsActual()
      {
  
          try
          {
              ProjectTotalsReportViewModel model = new ProjectTotalsReportViewModel();
  
              Employee currentUser = DataHelper.GetEmployee(User, db);
  
              model.AvailableEmployees = db.Employees.OrderBy(e =&gt; e.LastName).ThenBy(e =&gt; e.FirstName).ToList();
  
              if (currentUser.SecurityRoleCode == Constants.SECURITY_ROLE_CODE_ADMIN)
              {
                  model.AvailableProjects = (db.Projects.Any() ? db.Projects.Where(p =&gt; p.ProjectCategoryCode == Constants.PROJECT_CATEGORY_DIRECT).OrderBy(p =&gt; p.ProjectName).Distinct().ToList() : new List&lt;Project&gt;());
  
                  model.ProjectRate = (db.EmployeeProjectRates.Any() ? db.EmployeeProjectRates.Where(epr =&gt; epr.EmployeeID == epr.EmployeeID).OrderBy(epr =&gt; epr.EmployeeID).Distinct().ToList(): new List&lt;EmployeeProjectRate&gt;());
              }
              else
              {
                  model.AvailableProjects = (db.EmployeeProjectRates.Any(epr =&gt; epr.EmployeeID == currentUser.EmployeeID &amp;&amp; epr.ProjectRoleCode == Constants.PROJECT_ROLE_PROJECT_MANAGER) ? db.EmployeeProjectRates.Where(epr =&gt; epr.EmployeeID == currentUser.EmployeeID &amp;&amp; epr.ProjectRoleCode == Constants.PROJECT_ROLE_PROJECT_MANAGER).Select(epr =&gt; epr.Project).OrderBy(p =&gt; p.ProjectName).Distinct().ToList() : new List&lt;Project&gt;());
              }
  
              model.SelectedEmployeesForCheckBox = model.AvailableEmployees;
              model.SelectedProjectsForCheckBox = model.AvailableProjects;
  
              ViewBag.InitialLoad = true;
  
              return PartialView("_ExpectedVsActual", model);
          }
          catch
          {
              return null;
          }
      }
  
  
  [HttpPost]
      public ActionResult ExpectedVsActual(ProjectTotalsReportViewModel Model)
      {
          try
          {
              if (ModelState.IsValid)
              {
  
                  ViewBag.InitialLoad = false;
                  DataHelper.TimeFrame selectedTimeFrame = DataHelper.TimeFrame.Weekly;//Need to remove after adding selection for time frame
  
                  SMCContext db = new SMCContext();
                  ViewBag.TimeFrameSelectList = DataHelper.GetTimeFrameSelectList();
                  List&lt;ProjectTimeFrame&gt; timeFrames = new List&lt;ProjectTimeFrame&gt;();
                  ProjectViewModel Project = new ProjectViewModel();
                  timeFrames = DataHelper.GetProjectTimeFrames(Model.StartDate.Value, Model.EndDate.Value, selectedTimeFrame);
  
                  Project.EmployeeProjectRates = Project.EmployeeProjectRates.OrderBy(epr =&gt; epr.Employees.Single(e =&gt; e.Value == epr.EmployeeID.ToString())).ToList();
  
  
  
                      resultFile = currentPackage.GetAsByteArray();
                      return File(resultFile, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Expected Vs Actual.xlsx");
  
                  }
                  #endregion
              }
              else
              {
                  return PartialView("_ExpectedVsActual", Model);
              }
  
          }
          catch (Exception e)
          {
              throw e;
  
          }
  
  
  
  
  
  
  
      }
  </code></pre>
  
  <p>The bulk of all the formatting and creation of the file I left out, it is not related to the empty result. The result should look like this
  <img src="https://i.stack.imgur.com/aOaKM.jpg" alt="enter image description here"></p>