Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inserting a DateTimeOffset value truncates sub-seconds #249

Closed
ploeh opened this issue Dec 3, 2012 · 2 comments
Closed

Inserting a DateTimeOffset value truncates sub-seconds #249

ploeh opened this issue Dec 3, 2012 · 2 comments

Comments

@ploeh
Copy link

ploeh commented Dec 3, 2012

When inserting a record with the datetimeoffset column type, using a DateTimeOffset .NET structure seems to truncate the milliseconds of the inserted value.

As an example, I have a table defined in SQL Server 2012 Express like this:

CREATE TABLE [dbo].[JournalEntry](
    [EntryId] [int] IDENTITY(1,1) PRIMARY KEY CLUSTERED,
    [UserId] [int] NOT NULL REFERENCES [dbo].[User](UserId),
    [Time] [datetimeoffset](4) NOT NULL,
    [Distance] [int] NOT NULL,
    [Duration] [time] NOT NULL
)

I'm inserting data into it like this:

dynamic entry = new ExpandoObject();
entry.time = DateTimeOffset.Now;
entry.distance = 6000;
entry.duration = TimeSpan.FromMinutes(31);
entry.UserId = userId; // The userId value comes from another query
db.JournalEntry.Insert(entry);

As an example, when running while I'm writing this, according to my debugger, the time value is "2012-12-03T19:28:59.8001074+01:00".

However, after insertion into the database, the value, according to a SQL SELECT statement is "2012-12-03 19:28:59.0000 +01:00". Notice that the sub-second part of the value has been truncated.

As far as I can tell, this happens because Simple.Data.Ado.TypeHelper doesn't include DateTimeOffset in its BaseTypes set.

markrendle added a commit that referenced this issue Dec 3, 2012
@ploeh
Copy link
Author

ploeh commented Dec 3, 2012

The fix solves my issue. Thank you for the fast response.

I don't know what your protocol is for issues in this project, but for my sake the issue can be closed now :)

@markrendle
Copy link
Owner

Protocol!? Like I'm that organised. I fix it, you say it worked, I close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants