This is a migrated thread and some comments may be shown as answers.

Database First - Flat Inheritance

3 Answers 63 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Nikesh
Top achievements
Rank 1
Nikesh asked on 12 Sep 2012, 05:44 PM
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





3 Answers, 1 is accepted

Sort by
0
Nikesh
Top achievements
Rank 1
answered on 13 Sep 2012, 09:00 AM
Is there anyone from Telerik that can help with this issue?
0
Zoran
Telerik team
answered on 14 Sep 2012, 02:45 PM
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!
0
Nikesh
Top achievements
Rank 1
answered on 14 Sep 2012, 04:55 PM
Thanks Zoran

What you said makes complete sense. I have made all my Subclass properties nullable. Thank you very much for solving the issue :).
Tags
Data Access Free Edition
Asked by
Nikesh
Top achievements
Rank 1
Answers by
Nikesh
Top achievements
Rank 1
Zoran
Telerik team
Share this question
or