Skip to content

Oracle Overview ​

Weasel.Oracle provides schema management and migration support for Oracle databases using the Oracle.ManagedDataAccess.Core driver.

Installation ​

bash
dotnet add package Weasel.Oracle

Key Components ​

  • OracleProvider -- Singleton at OracleProvider.Instance that handles type mappings and identifier parsing. The default schema is WEASEL.
  • OracleMigrator -- Generates DDL scripts and executes schema migrations using PL/SQL blocks.

Supported Schema Objects ​

ObjectClassNamespace
TablesTableWeasel.Oracle.Tables
SequencesSequenceWeasel.Oracle

Connection String ​

Weasel.Oracle uses standard Oracle connection strings:

cs
var connectionString = "User Id=myuser;Password=mypass;Data Source=localhost:1521/XEPDB1;";

snippet source | anchor

Type Mappings ​

.NET TypeOracle Type
stringVARCHAR2(4000)
intNUMBER(10)
longNUMBER(19)
boolNUMBER(1)
decimalNUMBER
doubleBINARY_DOUBLE
DateTimeDATE
DateTimeOffsetTIMESTAMP WITH TIME ZONE
TimeSpanINTERVAL DAY TO SECOND
DateOnlyDATE (column only -- see below)
TimeOnlyINTERVAL DAY TO SECOND (column only -- see below)
GuidRAW(16)
byte[]BLOB

DateOnly and TimeOnly cannot be bound as parameters ​

Weasel generates a column type for both, so a schema can declare one -- but ODP.NET has no conversion for either CLR type, so neither can be used as a parameter value. Measured against ODP.NET 23.1.0.0, with the OracleDbType assigned before the value:

BindingResult
DateOnly as DateInvalidCastException -- ODP.NET binds a date through Convert.ToDateTime, and DateOnly is not IConvertible
DateOnly or TimeOnly as TimeStampORA-50028: Invalid parameter binding
TimeOnly as IntervalDSArgumentException: Value does not fall within the expected range
TimeOnly as Varchar2executes, and writes the current culture's ToString() -- e.g. 1:45 PM

Leaving the parameter untyped is not an alternative either: an untyped OracleParameter rejects the value outright, so there is nothing for the driver to infer from. ToParameterType therefore refuses with a NotSupportedException that names the conversion to make instead:

csharp
// DateOnly against a DATE column
provider.AddNamedParameter(command, "d", theDate.ToDateTime(TimeOnly.MinValue));

// TimeOnly against an INTERVAL DAY TO SECOND column
provider.AddNamedParameter(command, "t", theTime.ToTimeSpan());

Note that Entity Framework Core is unaffected: Oracle.EntityFrameworkCore applies its own value converter for both types, so an EF model mapping a DateOnly property keeps working.

Creating a Migrator ​

cs
var migrator = new OracleMigrator();

snippet source | anchor

Schemas in Oracle are implemented as database users. The migrator handles this automatically:

cs
await using var conn = new OracleConnection(connectionString);
await migrator.EnsureDatabaseExistsAsync(conn);

snippet source | anchor

Released under the MIT License.