title: Returning single value from SQL Stored Procedure using LINQ
body: <p>I have a stored procedure that returns a decimal value that I want to return using LINQ. I have used the following to return multiple values an using a ViewModel, but never to return a single value, and honestly struggling to find something online:</p>
  
  <pre><code>var CompanyIdParameter = new SqlParameter("CompanyId", companyId);
  departmentListVM = db.Database.SqlQuery&lt;DepartmentViewModel&gt;("sp_SELECT_Department_Hierarchy @CompanyId", CompanyIdParameter)
      .Select(x=&gt; new DepartmentViewModel()
      {
          pkiDepartmentId = x.pkiDepartmentId,
          DepartmentName = x.DepartmentName,
          ParentDepartmentId = x.ParentDepartmentId,
          ParentDepartmentName = x.ParentDepartmentName,
          fkiCompanyId = x.fkiCompanyId,
          isLastDept = x.isLastDept
      }).ToList();
  </code></pre>
  
  <p>Can I not do something like this:</p>
  
  <pre><code>var IdeaIdParameter = new SqlParameter("IdeaId", ideaId);
  var SessionIdParameter = new SqlParameter("SessionId", sessionId);
  var CriteriaIdParameter = new SqlParameter("CriteriaId", item.fkiJudgingCriteriaId);
  decimal result = db.Database.SqlQuery&lt;decimal&gt;("sp_SELECT_Department_Hierarchy @IdeaId, @SessionId, @CriteriaId", IdeaIdParameter, SessionIdParameter, CriteriaIdParameter)
                          .Select(x =&gt; x.value);
  </code></pre>
  
  <p>Am I making it too complicated or is there a better way?</p>