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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:12:59+00:00 2026-06-13T08:12:59+00:00

I am trying to do an equality comparison between a C# datetime and a

  • 0

I am trying to do an equality comparison between a C# datetime and a SQL datetime, which appears to fail due to the precision in which those values are stored.

So say I have a really simple SQL table, with these fields:

ID (PK, int, not null) - identity
Title (text, null)
UpdateTime (datetime, not null)

I create a class object via Entity framework, setting its UpdateTime to DateTime.Now like so:

DateTime now = DateTime.Now;
Title.UpdateTime = now;

When I insert my new object into the table, I see that all the values appear to be stored correctly. Now I want the ID that was created for my object.

This is where things get borked. I try pulling the ID back via LINQ:

Title.ID = context.DBTitles.Where(x=>x.UpdateTime == now).FirstOrDefault().ID;

This throws an exception because the query returns null, despite the fact that the ‘now’ I’ve inserted is supposedly the same as the ‘now’ that was inserted into my table.

So my question : How do I ensure that my C# datetime is equivalent to the datetime stored in SQL? What is the best way to get my ID back?

  • 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-13T08:13:00+00:00Added an answer on June 13, 2026 at 8:13 am

    If you’re using Linq, won’t the object you’re inserting get the ID assigned to it upon commit? You won’t need to ‘recall’ it.

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

Sidebar

Related Questions

I've been trying to understand the difference between JavaScript's comparison operators: identity and equality.
I'm trying to prove some simple things about a function which uses decidable equality.
just trying to test for equality in this piece of code, but getting a
I'm trying to override the equality (==) operator in C# to handle comparing any
I'm trying to compare words for equality, and the case [upper and lower] is
I am trying some code around object equality in java. As I have read
I'm trying to compare the equality of two multi-line strings. I'm getting one of
I'm trying to a somewhat sophisticated diff between individual rows in two CSV files.
I'm trying to use heterogenous equality to prove statements involving this indexed datatype: data
I'm trying to make a method that will match on reference equality for any

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.