oracle-databasenumbersentity-framework-6discriminatortph

EF6 TPH with Oracle


I'm currently having some problems when trying to use EF6 code first to map an existing Oracle database and create a Table Per Hierarchy. The script of the table I want to map goes like this:

CREATE TABLE TST.DATABASECON
(
    DATABASEID   NUMBER                         NOT NULL,
    CN_DATASOURCE  VARCHAR2(60 BYTE)              NOT NULL,
    CN_CATALOG     VARCHAR2(60 BYTE),
    CN_USERNAME    VARCHAR2(60 BYTE),
    CN_PASSWORD    VARCHAR2(60 BYTE),
    CN_INTEGRATED  NUMBER                         DEFAULT 0,
    CN_PROVIDER    NUMBER                         DEFAULT 0,
);

It is a table on an Oracle server containing database connection information - and every Oracle Database Information has a CN_PROVIDER = 0 whereas a SQL Database Information has a CN_PROVIDER = 1.

Therefore it was kind of natural for me to map this hierarchy using

modelBuilder.Entity<ReportConnection>()
                .Map<SqlConnection>(m =>   m.Requires("CN_PROVIDER").HasValue((int)1))
                .Map<OracleConnection>(m => m.Requires("CN_PROVIDER").HasValue((int)0));

However, when I try to access data, I always get the following error:

(60,12) : error 2016: Condition can not be specified 
on values of member 'CN_PROVIDER'. Value conditions 
are not supported for type 'OracleEFProvider.number'.

I have already tried to map this using:

Requires("CN_PROVIDER").HasValue((Int16)1)
Requires("CN_PROVIDER").HasValue((Int32)1)
Requires("CN_PROVIDER").HasValue((Int64)1)
Requires("CN_PROVIDER").HasValue((decimal)1)
Requires("CN_PROVIDER").HasValue((Decimal)1)

And I'm at my wit's end - does anyone knows whether if: 1- Is it possible to implement TPH in Oracle using a Number column as a Discriminator? 2- Am I missing something?

Right now I'll go ahead (and implement hierarchy using a factory on my repository layer) but I'm willing to try any solution proposed - thanks in advance!


Solution

  • I have also faced the same issue while using Numeric column as Discriminator. The solution I have used, should also work for you. As per that use the following code:

    modelBuilder.Entity<ReportConnection>()
                .Map<SqlConnection>(m =>   m.Requires("CN_PROVIDER").HasValue(1).HasColumnType("int"))
                .Map<OracleConnection>(m => m.Requires("CN_PROVIDER").HasValue(0).HasColumnType("int"));
    

    As you can notice, just need to specify the column type. This worked for me.