Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8948287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:56:52+00:00 2026-06-15T12:56:52+00:00

This works DateTime dtYesterday = DateTime.Now.AddDays(-1); data = data.Where(d => d.CreatedTime <= dtYesterday); But

  • 0

This works

DateTime dtYesterday = DateTime.Now.AddDays(-1);
data = data.Where(d => d.CreatedTime <= dtYesterday);

But this doesn’t

data = data.Where(d => d.CreatedTime <= DateTime.Now.AddDays(-1));

because EF cannot translate it into SQL. That’s fine.

But just out of curiosity, is there a way to force it to evaluate the value of DateTime.Now.AddDays(-1) before translating it to SQL?

I’m wondering if there is a syntax similar to this?

data = data.Where(d => d.CreatedTime <= ForceEvaluate(DateTime.Now.AddDays(-1)));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:56:53+00:00Added an answer on June 15, 2026 at 12:56 pm

    The difference between IQueryable<T> and IEnumerable<T> is that the former preserves the expression the programmer (i.e. you) wrote to present it to the query engine that performs the query (i.e. the RDBMS). Figuring out that DateTime.Now.AddDays(-1) is a function that needs to be evaluated would work, but that is too much magic compared to a simple and straightforward solution with familiar and easily recognizable syntax:

    DateTime dtYesterday = DateTime.Now.AddDays(-1);
    data = data.Where(d => d.CreatedTime <= dtYesterday);
    

    Having to guess would rob programmers of the opportunity to pass functions such as DateTime.Now.AddDays(-1) to the RDBMS: it is entirely conceivable that the current database date/time is different from your application server, potentially resulting in a different set of rows. On the other hand, introducing the ForceEvaluate syntax would be pointless, because if you must mark the expression to be evaluated, you might as well do it using the familiar way (see your code that I pasted above).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How come this works: import datetime now = datetime.datetime.now() month = '%d' % now.month
This works: scope :archived, :conditions => day_id IN (#{Day.where(year_id != #{DateTime.now.year}).collect{ |d| d.id }.join(,)})
I have created a procedure with this structure but it doesn't work for datetime
This works but for some reason the comma is missing. data gets inserted as
This works when I used a rectangle as the food but now I'm trying
This works ! >>> from datetime import date >>> today=date(2011,10,11) But how do I
Right now I'm doing: bool UseMetricByDefault() { return TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).TotalHours >= 0; } This works
This works: $aWeekAfterDate = new DateTime(); $aWeekAfterDate->modify('+1 week'); $aWeekAfterDate->format('d.m.Y'); But this: $aWeekAfterDate = new
I have this code: startWeekDate = startWeekDate == null ? DateTimeHelpers.calcMondayDate(DateTime.Now) : DateTimeHelpers.calcMondayDate(startWeekDate.Value); DateTime
This works in my dev machine, but not on my actual production server. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.