title: EntityFramework : The specified cast from a materialized 'System.String' type to the 'System.DateTime' type is not valid
body: <p>I have a SP which I am executing with help of <code>SqlQuery</code> method of <code>DbContext.Database</code>. I am calling it as follows:</p>
  
  <p><strong>EDIT 1:- passing <code>DateTime</code> now</strong></p>
  
  <pre><code>var t = form["datetime"];//value is 2013-May-08 09:30
  DateTime dtm;
  if (!DateTime.TryParse(t, out dtm))//successfully parses
       dtm = new DateTime(2013, 05, 8, 9, 30, 0);
  var rTime= new SqlParameter("@rTime", dtm);
  var result = UoW.ExecuteSp&lt;SPResult&gt;("spResult @rTime", rTime).ToList();
  </code></pre>
  
  <p>The last line throws the exception that specified cast from <code>string</code> to <code>DateTime</code> is not valid. </p>
  
  <p>Following is the definition of SP.</p>
  
  <pre><code>ALTER PROC [dbo].[spResult]
  (
      @rTime SMALLDATETIME --VARCHAR(32)
  )
  AS
  BEGIN
  --OTHER CODE
  END
  </code></pre>
  
  <p>If I directly execute the SP in SQL Management Studio it runs without any problem:</p>
  
  <pre><code>EXEC spResult ='2013-May-08 09:30'
  </code></pre>
  
  <p><strike>In SP the string is converted to date time as follows:</p>
  
  <pre><code>@resultAt SMALLDATETIME = CAST(@rTime AS SMALLDATETIME)
  </code></pre>
  
  <p></strike></p>
  
  <p>What is going wrong here?</p>