0 Replies Latest reply: Apr 3, 2013 10:40 AM by 1000833 RSS

    entity framework code first inheritance table per type problem

    1000833
      hello

      i am using ODP.NET version 11.2.0.3.20. i am trying to get entity framework code first to work. one problem i have encountered is with inheritance. i have a "table per type" inheritance scenario. i have 3 tables involved. the base table is called "S_PERIOD" which maps to the base "Period" class. i have a derived table called "S_SEASON_QUARTER" that maps to the derived "Quarter" class. And I have another derived table called "S_SEASON_PRICE_PERIOD" that maps to the derived "PriceBreak" class. for testing purposes i am trying to load all records. the problem is that every class instance ends up being of type "Quarter", which is incorrect. for whatever reason the provider thinks that every "S_PERIOD" record has a corresponding "S_SEASON_QUARTER" record. i took a look at the generated SQL and posted it down below. looking at this SQL it's clear to me why every object ends up being of type "Quarter". It looks like the provider is checking the "C2" field to determine the concrete type to instantiate. the problem however is that the "C2" field value provided by each derived table is ALWAYS equal to "1", which is a problem since this will result in the "case" statement always hitting the second "when" condition. does anyone have any idea how to fix this? thank you


      SELECT
      CASE WHEN (( NOT (("Project1"."C2" = 1) AND ("Project1"."C2" IS NOT NULL))) AND ( NOT (("Project2"."C2" = 1) AND ("Project2"."C2" IS NOT NULL)))) THEN '0X' WHEN (("Project1"."C2" = 1) AND ("Project1"."C2" IS NOT NULL)) THEN '0X0X' ELSE '0X1X' END AS "C1",
      CAST( "Extent1"."PERIOD_ID" AS number(10,0)) AS "C2",
      "Extent1"."START_DATE" AS "START_DATE",
      "Extent1"."END_DATE" AS "END_DATE",
      "Extent1"."NAME" AS "NAME",
      "Extent1"."TYPE_CODE" AS "TYPE_CODE",
      CAST( "Extent1"."CREATE_USER_ID" AS number(10,0)) AS "C3",
      "Extent1"."CREATE_DATE" AS "CREATE_DATE",
      CAST( "Extent1"."MODIFY_USER_ID" AS number(10,0)) AS "C4",
      "Extent1"."MODIFY_DATE" AS "MODIFY_DATE",
      CASE WHEN (( NOT (("Project1"."C2" = 1) AND ("Project1"."C2" IS NOT NULL))) AND ( NOT (("Project2"."C2" = 1) AND ("Project2"."C2" IS NOT NULL)))) THEN NULL WHEN (("Project1"."C2" = 1) AND ("Project1"."C2" IS NOT NULL)) THEN "Project1"."QUARTER_NAME" END AS "C5"
      FROM "DBO_SPACE_DEV"."S_PERIOD" "Extent1"
      LEFT OUTER JOIN (SELECT
           "Extent2"."QUARTER_NAME" AS "QUARTER_NAME",
           CAST( "Extent2"."QUARTER_ID" AS number(10,0)) AS "C1",
           1 AS "C2"
           FROM "DBO_SPACE_DEV"."S_SEASON_QUARTER" "Extent2" ) "Project1" ON ( CAST( "Extent1"."PERIOD_ID" AS number(10,0))) = "Project1"."C1"
      LEFT OUTER JOIN (SELECT
           CAST( "Extent3"."PRICE_PERIOD_ID" AS number(10,0)) AS "C1",
           1 AS "C2"
           FROM "DBO_SPACE_DEV"."S_SEASON_PRICE_PERIOD" "Extent3" ) "Project2" ON ( CAST( "Extent1"."PERIOD_ID" AS number(10,0))) = "Project2"."C1"

      Edited by: 997830 on Apr 3, 2013 8:40 AM