sapiens/SqlFu

DateTime in UTC?

Closed this issue · 9 comments

I am using SqlFu v2 with mysql and would like all DateTime's to be set to DateTimeKind.Utc. Can you recommend a way to do this for all SqlFu queries?

I can certainly force UTC manually on the DateTime properties for the objects I get back from SqlFu - but we have many different objects and I would rather not have to do the same thing over and over.

Thanks for your awesome library!
Cameron

Forgot to mention that all dates are being saved as UTC.

Hm, I always work with GMT dates and never had a problem, but anyways... try this in your app's start up class

PocoFactory.RegisterConverterFor<DateTime>(obj=>{ /* ensure it's UTC */}) 

Thanks for the quick response!

I have tried what you suggested but the converter never gets called:

   PocoFactory.RegisterConverterFor<DateTime>(o =>

        {

            return DateTime.SpecifyKind((DateTime) o, DateTimeKind.Utc);

        });

I placed this in my Application_Start and a few other places (just in case) with no luck. Any other thoughts?

Cheers

Cameron

From: Mike Mogosanu [mailto:notifications@github.com]
Sent: Friday, 3 June 2016 21:15
To: sapiens/SqlFu SqlFu@noreply.github.com
Cc: cameronmr cam@ctr.id.au; Author author@noreply.github.com
Subject: Re: [sapiens/SqlFu] DateTime in UTC? (#86)

Hm, I always work with GMT dates and never had a problem, but anyways... try this in your app's start up class

PocoFactory.RegisterConverterFor(obj=>{ /* ensure it's UTC */})


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub #86 (comment) , or mute the thread https://github.com/notifications/unsubscribe/AC8AS6y5yihs-_fQgCADUGUsHFiawGDhks5qICjKgaJpZM4ItWZ- .

Can you show me a code sample of the query itself?

Ok, I think I've found the problem. The mapper invokes directly reader.GetDateTime as an optimization and it doesn't check the converters. I'm thinking if I can come up with a simple solution.

Fixed it. You can update your nuget pack now (v.2.3.14).

Thanks Mike,

I tried the new package and the DateTime converter worked. Unfortunately, I was seeing consistent database timeouts (mysql/mariadb) when issuing multiple updates in a single transaction. Rolling back to SqlFu 2.3.12 resolved the timeout issue.

I haven’t had a chance to dig deeper. Any changes you are aware of that may be causing the timeout/deadlock – or anything I can do to help you identify the problem?

Thanks

Cameron

From: Mike Mogosanu [mailto:notifications@github.com]
Sent: Saturday, 4 June 2016 23:24
To: sapiens/SqlFu SqlFu@noreply.github.com
Cc: cameronmr cam@ctr.id.au; Author author@noreply.github.com
Subject: Re: [sapiens/SqlFu] DateTime in UTC? (#86)

Fixed it. You can update your nuget pack now (v.2.3.14).


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub #86 (comment) , or mute the thread https://github.com/notifications/unsubscribe/AC8ASxbS-yxOVhkGPl93oyM_0_uuANDlks5qIZhygaJpZM4ItWZ- .

Hi Mike,
I suspect the timeout I mentioned below has nothing to do with your changes. I will get back to you with a confirmation tomorrow.
Thanks
Cameron
On 7 Jun 2016 8:12 am, Cameron Rochester cam@ctr.id.au wrote:Thanks Mike, I tried the new package and the DateTime converter worked. Unfortunately, I was seeing consistent database timeouts (mysql/mariadb) when issuing multiple updates in a single transaction. Rolling back to SqlFu 2.3.12 resolved the timeout issue. I haven’t had a chance to dig deeper. Any changes you are aware of that may be causing the timeout/deadlock – or anything I can do to help you identify the problem? ThanksCameron From: Mike Mogosanu [mailto:notifications@github.com] Sent: Saturday, 4 June 2016 23:24To: sapiens/SqlFu SqlFu@noreply.github.comCc: cameronmr cam@ctr.id.au; Author author@noreply.github.comSubject: Re: [sapiens/SqlFu] DateTime in UTC? (#86) Fixed it. You can update your nuget pack now (v.2.3.14).—You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or mute the thread.

Hi Mike,

I can confirm there was a problem on our side and your changes work perfectly. Thanks again for the rapid response!

Cheers

Cameron

From: Cameron Rochester [mailto:cam@ctr.id.au]
Sent: Tuesday, 7 June 2016 18:16
To: 'sapiens/SqlFu' reply@reply.github.com
Subject: RE: [sapiens/SqlFu] DateTime in UTC? (#86)

Hi Mike,

I suspect the timeout I mentioned below has nothing to do with your changes. I will get back to you with a confirmation tomorrow.

Thanks
Cameron

On 7 Jun 2016 8:12 am, Cameron Rochester <cam@ctr.id.au mailto:cam@ctr.id.au > wrote:

Thanks Mike,

I tried the new package and the DateTime converter worked. Unfortunately, I was seeing consistent database timeouts (mysql/mariadb) when issuing multiple updates in a single transaction. Rolling back to SqlFu 2.3.12 resolved the timeout issue.

I haven’t had a chance to dig deeper. Any changes you are aware of that may be causing the timeout/deadlock – or anything I can do to help you identify the problem?

Thanks

Cameron

From: Mike Mogosanu [mailto:notifications@github.com]
Sent: Saturday, 4 June 2016 23:24
To: sapiens/SqlFu <SqlFu@noreply.github.com mailto:SqlFu@noreply.github.com >
Cc: cameronmr <cam@ctr.id.au mailto:cam@ctr.id.au >; Author <author@noreply.github.com mailto:author@noreply.github.com >
Subject: Re: [sapiens/SqlFu] DateTime in UTC? (#86)

Fixed it. You can update your nuget pack now (v.2.3.14).


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub #86 (comment) , or mute the thread https://github.com/notifications/unsubscribe/AC8ASxbS-yxOVhkGPl93oyM_0_uuANDlks5qIZhygaJpZM4ItWZ- .