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

Add support for OracleTimestampWithTimezone to Oracle EF Core Provider #268

Open
gscpw opened this issue Nov 25, 2022 · 0 comments
Open

Comments

@gscpw
Copy link

gscpw commented Nov 25, 2022

Oracle has a type TIMESTAMP WITH TIME ZONE, and it is recommended to use the TZR TZD format, which looks like this as a PL/SQL literal:

TIMESTAMP '1999-10-29 01:30:00 America/Los_Angeles PDT'

The appropriate .NET type for timestamp supported by Oracle EF Provider is DateTimeOffset. The problem is, DateTimeOffset has no way to specify TZR (such as America/Los_Angeles) and neither TZD (such as PDT in the example above).

There exists the OracleTimestampWithTimezone in Oracle ADO.NET driver, which does support specifying DateTime + timezone, for example:

var connection = db.Database.GetDbConnection();
connection.Open();

using var param = new OracleParameter();
param.OracleDbType = OracleDbType.TimeStampTZ;
param.Value = new OracleTimeStampTZ(DateTime.Parse("1999-10-29 01:30:00"), "America/Los_Angeles");

using var cmd = connection.CreateCommand();
cmd.CommandText = "INSERT INTO tz_test (tz_value) VALUES (:1)";
cmd.Parameters.Add(param);

cmd.ExecuteNonQuery();

However, it seems impossible to replicate this functionality using Oracle EF Provider. If I create an entity and add a property of type OracleTimestampWithTimezone, I get an exception:

'The property 'TzTest.TzValue' could not be mapped because it is of type 'OracleTimeStampTZ', which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.'

Could you please add support to Oracle EF Core Provider for OracleTimestampWithTimezone? My goal is to store a value in TIMESTAMP WITH TIME ZONE in TZR TZD format without data loss, is there any way to achieve this with Oracle EF Core?

Thank you.


For reference, I am already discussing this in EF Core repository, but so far it looks like this is something Oracle needs to add support for.

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

No branches or pull requests

2 participants