Skip to main content
Home Forums Silverlight Programming WCF RIA Services DateTime are always Local using RIA and Linq to SQL - need it to be UTC
2 replies. Latest Post by manolovalenzuela on July 10, 2009.
(0)
ericsson007
Member
43 points
36 Posts
05-05-2009 11:42 AM |
Is there a (simple/preferred) way to specify that Linq To SQL classes used in my DomainService should consider a DateTime property as UTC (i.e. having the Kind property of the DateTime type to be Utc by default), or is there a 'clean' workaround?
I tried overriding DomainService.UsesUtcDateTimes to return true (as mentioned in http://silverlight.net/forums/t/87574.aspx), but it didn't help in my case.
I'm using Linq to SQL with RIA Services. The time zone on my app-server is not the same as the SQL 2005 Server (cannot change any), and none is UTC. When I persist a property of type DateTime to the dB I use the UTC value (so the value in the db column is UTC), but when I read the values back (using Linq To SQL) I get the .Kind property of the DateTime value to be 'Unspecified'.
The problem is that the UTC value is now 4 hours off (or whatever timezone offset I happen to have on the server). Which of course also means I don't get the correct time when it ends up on the client. I would expect this scenario to be common for most Silverlight applications using RIA and Linq to SQL.
I guess I could add a partial classes with a new property, but I rather have a way to simply specify that the DateTime Property CreatedDateTime is persisted in the dB as UTC in the Db, and that's it.
05-07-2009 10:38 PM |
To close this post off, I ended up with a solution based on http://social.msdn.microsoft.com/Forums/en-US/linqprojectgeneral/thread/2aa5f2f1-00ec-496e-ad60-fb2c0f35f521
[
I guess the 'correct' solution is to use SQL Server 2008 and the type DateTimeOffset instead of DateTime.....
manolova...
4 points
11 Posts
07-10-2009 11:17 AM |
Hi, i'm from Chile, and our time is -4 !!.
There is a method in the Date class: ToUTCTime() and ToLocalTime()
with this methods you can swap from one to other format time.
You can create a Converter Class and use it on your xaml:
Imports
End
xaml:
<
...
i hope this help to you!