title: How to get output result from stored procedure use Entity Framework in C#?
body: <p>I'm working on an ASP.NET MVC project; my goal is to prepare a report from a table so, the first time I've wrote Linq code but it was too slow. </p>
  
  <p>And after that I've written a SQL query it was so fast and I want to use stored procedure for getting report data from my table. In fact my project is so easy: it gets two dates - start date and end date - and displays result in a table.</p>
  
  <p>I want to write my stored procedure to get two parameters - start date and end date - from C# code and then return output in a variable in C#. </p>
  
  <p>The first question: how to convert my SQL query to a stored procedure with two parameters, start Date and End date?</p>
  
  <p>The second question: how to return output result in C#?</p>
  
  <pre><code>SELECT 
      CAST(date_rec_slash AS DATETIME), COUNT(code_marz) AS total,
      CASE
         WHEN code_marz = 1 THEN 'a'
         WHEN code_marz = 2 THEN 'b'
         WHEN code_marz = 3 THEN 'c'
         WHEN code_marz = 4 THEN 'd'
         WHEN code_marz = 5 THEN 'e'
      END
  FROM 
      dbo.tbl_bar 
  WHERE 
      CAST(date_rec_slash AS DATETIME) BETWEEN '2017/12/01' AND '2017/12/31'
  GROUP BY 
      CAST(date_rec_slash AS DATETIME), code_marz
  ORDER BY 
      CAST(date_rec_slash AS DATETIME) ASC;
  </code></pre>
  
  <p>C#:</p>
  
  <pre><code>var spResults = db.Database.SqlQuery&lt;tbl_bar&gt;("Report");
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/5326X.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/5326X.jpg" alt="enter image description here"></a></p>