I have data stored in a TIMESTAMP WITH TIME ZONE oracle column, and now I'm trying to read it back to the C # DateTimeOffset variable using Dapper. The problem is that dapper ignores the offset value in the database and always fills my variable with the current environment offset.
Is there an easy way to get dapper to recognize the offset value from the database?
Basically, I want something in these lines to work:
var input=new DateTimeOffset(2016, 3, 15, 14, 30, 0, TimeSpan.Zero); DateTimeOffset output; using(var connection=new OracleConnection(QueryConnectionString)) { output=connection.ExecuteScalar<DateTimeOffset>("Select to_timestamp_tz('"+input.ToString("yyyy-MM-dd HH:mm zzz")+"', 'YYYY-MM-DD HH24:MI TZH:TZM') From DUAL"); } Assert.AreEqual(input, output);
As written, this gives an invalid lit exception, it seems like dapper reads it as a DateTime, and then tries to pass it to DateTimeOffset, ignoring the offset value.
My code, which queries the table and populates the class object defined by these types, does not throw an error, but fills the instance of the object with a local offset, not a value in the database. So instead of 2016-03-15 14:30 +0
I would 2016-03-15 14:30 -5
into 2016-03-15 14:30 -5
if I were working with the input value above.
source share