oracle / oracle/dotnet-db-samples
Add support for OracleTimestampWithTimezone to Oracle EF Core Provider
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 434
- Forks
- 191
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 1
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the OracleTimeStampTZ and OracleParameter usage shown in the issue, then read the linked EF Core discussion for the existing constraints. Done means an Oracle EF Core entity property can use OracleTimeStampTZ and persist TIMESTAMP WITH TIME ZONE values with TZR and TZD information without data loss.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100