Referencing Target-Per-Hierarchy Objects

Posts   
 
    
jd
User
Posts: 6
Joined: 10-Nov-2005
# Posted on: 18-Nov-2005 06:02:20   

Hello all. I'm trying to develop a generic database structure using the new target-per-hierarchy stuff, and I have some questions.

Situation:

Let's assume I have 2 tables: Container and Metadata, where metadata is the target-per-hierarchy table. I've declared the associated MetadataEntity abstract, and using a discriminator, have created two subtypes. ContainerType, and ContainerStatus.

I then have 2 foreign keys in the Container table that link to the Metadata table. 1 for the type, and 1 for the status. The problem is that when I create this relationship, the ContainerType and ContainerStatus properties are of type Metadata. Is there a way to make these the appropriate subtypes?

If not, any other suggestions.

What if i want m:n relationships to a subtyped object. So assume that I now have a table called Metadata_Join. The Metadata_Join entity is abstract, and I have subtyped it as well. ContainerSolution and ContainerService. I would like to have 2 collections off of the Collateral table. CollateralSolutionCollection, and CollateralServiceCollection. I'd like for these types to also be typed correctly.

Is this doable? Is there a better way to handle this than the path I'm heading down?

Thanks all.

sparmar2000 avatar
Posts: 341
Joined: 30-Nov-2003
# Posted on: 19-Nov-2005 17:07:44   

Hello all. I'm trying to develop a generic database structure using the new target-per-hierarchy stuff, and I have some questions

I am not familier with target-per-hierarchy. Please can you expand/expalin

jd
User
Posts: 6
Joined: 10-Nov-2005
# Posted on: 19-Nov-2005 17:14:03   

sparmar2000 wrote:

Hello all. I'm trying to develop a generic database structure using the new target-per-hierarchy stuff, and I have some questions

I am not familier with target-per-hierarchy. Please can you expand/expalin

Sure. Target per Hierarchy is a new feature of the latest release and it allows you to create an inheritance hierarchy for your objects. Take a look at the help file under Concepts - Entity inheritance and relational models first to see what this lets you do, and then look at Designer - Inheritance mapping afterward to see how to do it.

My problem is that while I can set up all of the inherited entities, I don't know how to reference them from another entity. All I can get is the supertype.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 19-Nov-2005 18:52:04   

target-per-hierarchy

To avoid confusion, it's: - Target Per Entity and - Target Per Entity Hierarchy.

So target-per-hierarchy == targetperentity hierarchy wink

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 19-Nov-2005 18:58:57   

jd wrote:

Hello all. I'm trying to develop a generic database structure using the new target-per-hierarchy stuff, and I have some questions.

Situation:

Let's assume I have 2 tables: Container and Metadata, where metadata is the target-per-hierarchy table. I've declared the associated MetadataEntity abstract, and using a discriminator, have created two subtypes. ContainerType, and ContainerStatus.

I then have 2 foreign keys in the Container table that link to the Metadata table. 1 for the type, and 1 for the status. The problem is that when I create this relationship, the ContainerType and ContainerStatus properties are of type Metadata. Is there a way to make these the appropriate subtypes?

No, because the relation is with MetaData and metadata can be any type in its hierarchy. Though when you traverse / utilize that relation, the object returned will be of a subtype of MetaData, so you have to cast / use is/as, or you can read the discriminator field and base your logic on that to which type to cast the returned object. Because: Container.MetaData has to have a type, even though MetaData can be a lot of types.

If not, any other suggestions.

What if i want m:n relationships to a subtyped object. So assume that I now have a table called Metadata_Join. The Metadata_Join entity is abstract, and I have subtyped it as well. ContainerSolution and ContainerService. I would like to have 2 collections off of the Collateral table. CollateralSolutionCollection, and CollateralServiceCollection. I'd like for these types to also be typed correctly.

Is this doable? Is there a better way to handle this than the path I'm heading down?

Thanks all.

If I understand it correctly, this should be possible. However you should define relations between Container and ContainerSolution, and between Solution and ContainerSolution to form the m:n relation, IF you want it typed. Otherwise it's polymorphic.

Frans Bouma | Lead developer LLBLGen Pro