title: LINQ to entities : cannot call a method
body: <p>I'm aware there are alreay a lot of posts concerning this issue, but i can't seem to find a solution for this.</p>
  
  <p>Here's my Ling to Entities query :</p>
  
  <pre><code>IEnumerable&lt;Tblstamp&gt; changes = (from c in userGSN.edb.Tblstamp
                                   where (c.Ts_Date &gt;= userGSN.DateLastCheck &amp;&amp; 
                                          TimeSpan.Parse(c.Ts_Time) &gt;= userGSN.TimeLastCheck)
                                   orderby c.Ts_Id ascending
                                   select c);
  </code></pre>
  
  <p>I want to compare <code>c.Ts_time</code> to <code>userGSN.TimeLastCheck</code>, but for that I have to convert the <code>c.Ts_Time</code> to a timespan (it is a string, and comes from a database I can't modify, tried everything). I also can't do the converting before the query in an other variable since I can't access it outside of the query.</p>
  
  <p>Obviously, I get an error for trying to use the TimeSpan.Parse method in my query, but I can't find any workaround to this. I have tried using LINQ to Object but since I am really not used to it I couldn't make the equivalent query that i have here.</p>
  
  <p>I am aware of the problem, I'm just trying to find a workaround and need some help please !</p>
  
  <p>EDIT : 
  So I tried the <code>DateDiff</code> function as suggested : </p>
  
  <pre><code>IEnumerable&lt;Tblstamp&gt; changes = (from c in userGSN.edb.Tblstamp
                                               where (c.Ts_Date &gt;= userGSN.DateLastCheck &amp;&amp; SqlFunctions.DateDiff("second",userGSN.TimeLastCheck,c.Ts_Time).Value &gt; 0 )
                                               orderby c.Ts_Id ascending
                                               select c
                                               );
  </code></pre>
  
  <p>but it gives me the same error : <code>"LINQ to Entities does not recognize the method 'System.Nullable</code>1[System.Int32] DateDiff(System.String, System.Nullable<code>1[System.TimeSpan], System.String)' method, and this method cannot be translated into a store expression."</code></p>
  
  <p>Even though it clearly says <a href="https://msdn.microsoft.com/en-us/library/dd466158(v=vs.110).aspx" rel="nofollow">here</a> "You cannot call this function directly. This function can only appear within a LINQ to Entities query.", which is exactly what I'm doing ?!</p>