title: How can I express GetDate() and DateAdd() methods in EF Core and LINQ?
body: <p>I am using SQL Server and Entity Framework Core 2. I have the following SQL query which (in SQL Server Management Studio) correctly gives me the measurements that were added the previous hour (to the measurements table):</p>
  
  <pre><code>SELECT id, [timestamp] 
  FROM measurement 
  WHERE
    dateADD(MINUTE, 60, [timestamp]) &gt; getdate()
  </code></pre>
  
  <p>This works well. But now I'd like to write this query in LINQ using EF Core 2.
  Of course I could write the following code:</p>
  
  <pre><code>dbContext
     .Measurement
     .Include(m =&gt; m.Section)
     .GroupBy(m =&gt; m.Section, (section, m) =&gt; new Section
      {
         Name = section.Name,
         CustomerId = section.CustomerId,
         MostRecentMeasurement = m.Max(z =&gt; z.Timestamp)
      })
     .Where(x =&gt; x.MostRecentMeasurement &gt; DateTime.Now.AddHours(-1))
     .ToList();
  </code></pre>
  
  <p>but this has the following drawbacks:</p>
  
  <ul>
  <li>DateTime.Now cannot be translated to SQL hence this will be evaluated at the client which does not perform that well,</li>
  <li>The timezone at the client differs from the database server timezone, needing extra complexity and computation.</li>
  </ul>
  
  <p>How can I express the query in EF Core such that it can be completely translated to SQL?</p>