Database First - Flat Inheritance

4 posts, 0 answers
  1. Nikesh
    Nikesh avatar
    12 posts
    Member since:
    Nov 2011

    Posted 12 Sep 2012 Link to this post

    Hi

    Got a bit of a problem designing my model using Database First with Flat Inheritance. I got a sql view called Trade and it has the following properties:

    TradeId
    AccountId
    CptyId
    BuyCcyId
    BuyCcyId2
    BuyQuantiy1
    BuyQuantity2

    EffectiveDate
    CDSSpread

    RepoRate


    I have created an entity called "Trade" which maps to this view and then created the following entities that inherit from the Trade entity. Their respective properties are in brackets


    Trade - (TradeId, AccountId, CptyId)
    TradeFx - (BuyCcyId, BuyCcyId2, BuyQuantiy1, BuyQuantity2)
    TradeInvestment - (EffectiveDate, CDSSpread)
    TradeRepo - (RepoRate)

    I've mapped the above properties to the Trade view in the Mapping Details Editor.

    I've tried to follow the procedure outlined in this link http://www.telerik.com/help/openaccess-orm/openaccess-tasks-define-model-inheritance-flat-mapping.html, however I can NOT complete step 17 as "Use default mapping" is greyed out. I compiled the code and get the following error:

    Error 1 The derived persistent type 'Tradar.Data.TradeStockLoan' is part of a flat inheritance hierarchy but contains properties mapped to not-nullable columns. C:\BackOfficeRepos\TradarBE\DataAPI\Data Service\Tradar.Data\DataAPIv2\TradarDiagrams.rlinq 0 0
    Error 2 The derived persistent type 'Tradar.Data.TradeRepo' is part of a flat inheritance hierarchy but contains properties mapped to not-nullable columns. C:\BackOfficeRepos\TradarBE\DataAPI\Data Service\Tradar.Data\DataAPIv2\TradarDiagrams.rlinq 0 0
    Error 3 The derived persistent type 'Tradar.Data.TradeTransfer' is part of a flat inheritance hierarchy but contains properties mapped to not-nullable columns. C:\BackOfficeRepos\TradarBE\DataAPI\Data Service\Tradar.Data\DataAPIv2\TradarDiagrams.rlinq 0 0 Error 4 The derived persistent type 'Tradar.Data.TradeFx' is part of a flat inheritance hierarchy but contains properties mapped to not-nullable columns. C:\BackOfficeRepos\TradarBE\DataAPI\Data Service\Tradar.Data\DataAPIv2\TradarDiagrams.rlinq 0 0

    Can anyone shed any light on what I'm doing wrong or what this error means? Regards Nikesh





  2. Nikesh
    Nikesh avatar
    12 posts
    Member since:
    Nov 2011

    Posted 13 Sep 2012 Link to this post

    Is there anyone from Telerik that can help with this issue?
  3. DevCraft banner
  4. Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 14 Sep 2012 Link to this post

    Hi Nikesh, 

    The fact that you are seeing this error, does not stop your project from compilation, but it does show that this is a problematic scenario from the perspective of OpenAccess. Here are the reasons why:
    • When you map more than one entity to the same table (flat inheritance), and you want to insert a record of certain derived type, values are inserted only in the columns mapped to that entity. For all other columns in the table the value is NULL.
    • It seems that you have non-nullable columns mapped to properties in some of your entities like TradeRepo . When records from other derived classes like TradeFx are inserted in the table, the NULL value will be inserted in the columns that are only mapped in TradeRepo. Those insert calls will fail as part of the columns mapped in TradeRepo are not nullable.

    Generally, when flat inheritance is used, it is better to have columns that allow NULL in the database table to avoid such issues.

    Regards,
    Zoran
    the Telerik team
    Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
  5. Nikesh
    Nikesh avatar
    12 posts
    Member since:
    Nov 2011

    Posted 14 Sep 2012 Link to this post

    Thanks Zoran

    What you said makes complete sense. I have made all my Subclass properties nullable. Thank you very much for solving the issue :).
Back to Top