title: How to pass a datetime parameter from Entity Framework SqlQuery and SqlParameter to a Stored Procedure?
body: <p>This is my code on server:</p>
  
  <pre><code>model.Grid.DataSource =
         db.Database.SqlQuery&lt;Reports.Cardex&gt;("[dbo].[SP_RptCardexSummary_English_1] @OwnerCode, @TypeCode, @MeasurementUnitCode, @FDate",
         new SqlParameter { ParameterName = "@OwnerCode", Value = filterList[0] },
         new SqlParameter { ParameterName = "@TypeCode", Value = filterList[1] },
         new SqlParameter { ParameterName = "@MeasurementUnitCode", Value = filterList[2] },
         new SqlParameter { ParameterName = "@FDate", Value = filterList[3] })
         .ToList();
  </code></pre>
  
  <p>and my procedure:</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[SP_RptCardexSummary_English_1] 
  
  @OwnerCode int,
  @TypeCode int,
  @MeasurementUnitCode smallint,
  @FDate datetime
  </code></pre>
  
  <p>UPDATE:
  I created a DateTime value by String:</p>
  
  <pre><code>var date = "2015/05/25";
  var time = "20:30"
  filterList.Add(Convert.ToDateTime(date + " " + time));
  </code></pre>
  
  <p>But when I pass a <code>System.DateTime</code> value, it throws an exception:</p>
  
  <blockquote>
    <p>"The specified cast from a materialized 'System.DateTime' type to the 'System.String' type is not valid."</p>
  </blockquote>
  
  <p>How should I pass it?<br>
  And interesting thing is, when I set SQL Profiler for observing and run what SQL Profiler received, It works fine!! What's the problem?</p>