Inherited Relations

Posts   
 
    
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 07-Apr-2009 05:05:52   

Hi there,

I have generated classes A and B where B inherits from A.

I've noticed that B's relations are inherited from A. So if I have a third table C which is related to A and I want to join C to B then how do I do this? I can join C to A but what if I only want it to join when an A is also a B? simple_smile

If the inheirtance relationship between A and B wasn't established then I could just do C joins to A and then join A to B but LLBLGen doesn't automatically create a relation between A and B.

Hope that makes sense!

Cheers, Ian.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 07-Apr-2009 07:11:26   

I can join C to A but what if I only want it to join when an A is also a B?

You could: 1. Hide the _A.SomeCId -C.SomeCId _relation (both sides). 2. Create a relation between B.SomeCId - C.SomeCId. Note that B.SomeCId is an inherited field from A.

David Elizondo | LLBLGen Support Team
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 07-Apr-2009 15:26:04   

OK! Why doesn't LLBLGen automatically generate this relation which would have been there had it not been for the inheritance between the entities?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 08-Apr-2009 04:16:37   

LLBLGen automatically generates the relations based on your DB schema metadata. The normal usage for relations in a hierarchy is that the subtypes inherit the supertype relations. But you want to add the relation only to subtype. That must be done manually.

David Elizondo | LLBLGen Support Team
rdhatch
User
Posts: 198
Joined: 03-Nov-2007
# Posted on: 22-Sep-2009 19:09:58   

Hi David,

I'm in this same situation.

I want to be able to go from C -> A (BaseType) and from C -> B (SubType)

To go from C -> B, I would need to hide the relation from C -> A? Can I only have one or the other?

Please confirm the best way to access both related entities & their subtypes. Thank you very much!

Ryan

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 23-Sep-2009 12:02:47   

When you need to go from C -> B (SubType), you may use the relation from C -> A and use a Type Filter for B.

rdhatch
User
Posts: 198
Joined: 03-Nov-2007
# Posted on: 23-Sep-2009 15:09:52   

Hi Walaa -

If I do that, won't I suffer these very ugly side effects?

1.) I will have to manually build all the SubType prefetch paths 2.) What's worse - I won't be able to get a strongly typed collection, correct? So the Filter approach won't let me do:

  • BaseTypeCollection > SubTypeCollection
  • EntityView(of BaseType) > EntityView(of SubType)
  • EntityCollectionBase(Of BaseType) > EntityCollectionBase(Of SubType) I need strongly-typed collections... We're using generics extensively for Entities & EntityCollections. We have several layers of inheritance. I don't want to be stuck passing the SuperBaseTypeCollection around to all my higher-level functions.

What's the best approach here for C -> A & C -> B? Couldn't we simply create both in the designer? I've tried, and I get compile errors.

Please tell me these 2 relations aren't mutually exclusive. Many thanks!

Ryan

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 23-Sep-2009 15:41:08   

I don't think any of these are applicable if you used a collection of the SubType.

e.g. Say you want to fetch Bs(sub) filtered by some field on C using the relation from C to A(super). The following code should do the job.

var bucket = new RelationPredicateBucket(C_Fields.SomeField == xyz);
bucket.Relations.Add(SuperEntity.Relations.C_Entity...)

var subs = new EntityCollection<SubEntity>();
adapter.FetchEntityCollection(subs, bucket);
rdhatch
User
Posts: 198
Joined: 03-Nov-2007
# Posted on: 23-Sep-2009 17:31:50   

Hi Walaa -

Yes, but then my EntityGraph will be disconnected. Merging / Diffing the EntityGraph won't work. EntityGraph listening for deletes will not detect B's deletes. Recursive Saves of C will not work. Because C (my Root Entity) has no clue B even exists.

The goal is to walk the relations in the Graph. I need actual relations from C -> A and C -> B.

I have no problem manually creating these relations in the designer. But it's not working for me.

This seems simple. Shouldn't this be possible?

Ryan

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 24-Sep-2009 11:30:17   

I have no problem manually creating these relations in the designer. But it's not working for me.

Would you please explain in more details the "it's not working for me" part. Thanks.