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 3434348
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:41:16+00:00 2026-05-18T07:41:16+00:00

Inside a compiled LINQ query as a condition part, I was using Datetime.Now .

  • 0

Inside a compiled LINQ query as a condition part, I was using Datetime.Now . It used to give me irrelevant results. I think it used to store same Datetime.Now value for few subsequent calls. To solve this issue I send Datetime.Now as a value parameter to the compiled query and it is working fine.

Old Code

     event.EventEnd >= Datetime.Now

New Code

     event.EventEnd >= currentTime

Where currentTime is a variable contains Datetime.Now value received outside from compiled query.

Please let me know if this is the default behavior of complied LINQ query or I was wrong somewhere

Platform : ASP.NET 4.0, MVC 2.0

Irrelevant results means , say we have one record with eVent.EventEnd value is 10-10-10 02:10 PM , if I run the query at 10-10-10 02:00 PM , we get that record in the result. If I run the query at 10-10-10 03:00 PM also we get that record in result. Which is wrong. But after I use the variable instead on DateTime.Now , it is working fine.

Compiled LINQ Query

public static Func<DataContext, CommonParams, string, DateTime, IQueryable<EventEntity>> GetEventsByOwnerID 
= CompiledQuery.Compile(
(DataContext context, CommonParams inputParams, string eventType, DateTime currentTime ) =>
   (from eVent in context.Events
    join categories in context.Categories on eVent.CategoryID equals categories.CategoryID
    where  !eVent.IsDeleted 
    && eVent.OwnerID == inputParams.UserID
    && (eventType == "ALL" ||
        (eventType == "CURRENT" && eVent.EventEnd >= currentTime) ||
        (eventType == "OLD" && eVent.EventEnd < currentTime))
    orderby eVent.PostedOn descending
    select new EventEntity()
    {
        EventID = eVent.EventID,
        CategoryID = eVent.CategoryID,
        Title = eVent.Title,
        Owner = eVent.OwnerName,
        EventStart = eVent.EventStart,
        EventEnd = eVent.EventEnd,
        Host = eVent.Host,
        Location = eVent.Location,
        Description = eVent.Description,
        Email = eVent.Email,
        URL = eVent.URL,
        Phone = eVent.Phone,
        CategoryName = categories.CategoryName,
        ProgramName = eVent.ProgramName,
        IsTelevised = eVent.IsTelevised,
        ChannelName = eVent.ChannelName,
        CityID = eVent.CityID,
        CountryID = eVent.CountryID,
        IsActive = eVent.IsActive,
        OwnerID = eVent.OwnerID,
        IsEndTimePartEmpty = eVent.IsEndTimePartEmpty,
        IsStartTimePartEmpty = eVent.IsStartTimePartEmpty,
        IsDeleted = eVent.IsDeleted,
        ThumbnailURL = eVent.ThumbnailURL,
        AttendeeCount = eVent.AttendeeCount,
        CommentsCount = eVent.CommentsCount
    })
);
  • 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-05-18T07:41:16+00:00Added an answer on May 18, 2026 at 7:41 am

    I saw the same issue. I verified using SQL Profiler that it had cached the value of DateTime.Now.

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

Sidebar

Related Questions

I'm using a LINQ query to translate data inside a DataTable object to be
Right, I've usually used 'using' directives as follows using System; using System.Collections.Generic; using System.Linq;
Is it possible to use a dynamic Linq Expression inside a Query Expression? Something
I have a C++ 'Control Library Project' compiled using /CLR. Inside this project there
When we compile a dll using __stdcall inside visual studio 2008 the compiled function
Is it possible to have a Android VNC server compiled lib inside my android
I've downloaded and compiled the Microsoft detouring library. Inside my project I've included the
Inside the LAN, we are good to go… folks access our intranet using http://
I have compiled Mozilla NPAPI plugin example npruntime on Mac OSX 10.5. It give
I'v created a C header file (It's compiled), now when i compile my program

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.