EntityFramework not getting results when comparing timestamp on version 6.5.1

Jose Lara 0 Reputation points
2024-09-30T18:15:49.7433333+00:00

We recently update our version on Entity Framework from 6.4.4 to 6.5.1 and I start seeing issues in our jobs when trying to pull data by timestamp.

on the LINQ query we have we match by timestamp and we start getting zero results when we expect data as we are matching a timestamp that exists on the database.

Note: I was pulling the first row from database(to based on some logic) then I use this row to pull the data by timestamp,

I did the logic below to match the timestamp as a workaround. I notice the issue I had was with Milliseconds, if I try to match timestamp including milliseconds I get empty results and if I don't include it I get expected results and I verify the millisecond match but for some reason I does not work when the millisecond is include on the logic, any help will appreciate.

&& DbFunctions

 .CreateDateTime(w.ReportTimeStamp.Year, 

     w.ReportTimeStamp.Month, 

     w.ReportTimeStamp.Day, 

     w.ReportTimeStamp.Hour, 

     w.ReportTimeStamp.Minute,

     w.ReportTimeStamp.Second) ==

 DbFunctions

 .CreateDateTime(hist.ReportTimeStamp.Year,

     hist.ReportTimeStamp.Month,

     hist.ReportTimeStamp.Day,

     hist.ReportTimeStamp.Hour,

     hist.ReportTimeStamp.Minute,

     hist.ReportTimeStamp.Second)
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,865 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Jack J Jun 24,491 Reputation points Microsoft Vendor
    2024-10-01T03:49:04.86+00:00

    @Jose Lara, Welcome to Microsoft Q&A, based on my test, I reproduce the same problem that x.ReportTimeStamp == y.ReportTimeStamp --> this gives me zero results.

    I used almost the same code in ef6 and ef core, but I get different results.

       var test1 = context.Examples.Where(m => m.Id == 1003).OrderByDescending(m => m.ReportTimeStamp).FirstOrDefault();
       var result = context.Examples.Where(m => m.ReportTimeStamp == test1.ReportTimeStamp).ToList();
    

    database:

    User's image

    In ef 6.5.1

    User's image

    In ef core:

    User's image

    Therefore, I recommend that you could submit an issue in Github.

    Hope it could help you.

    Best Regards,

    Jack


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.