Inheritence - Fetching objects based on PK

Posts   
 
    
mshe
User
Posts: 167
Joined: 02-Feb-2006
# Posted on: 03-Jan-2007 10:17:04   

Hello,

I'm using the inheritence features in LLBLGen Pro 2.0 using TargetPerEntity (1 entity per table).

I have a table called BaseObject and another table called ChildObject.

ChildObject inherits from BaseObject.

Given a set of PKs, how can I return an entitycollection which contains ChildObjects + BaseObjects?

For example, if my data is like:

1 - Base object 2 - ChildObject 3 - Base Object 4 - Base Object

and I pass in a set of keys: 2,3, I should get back an entityCollection with:

2 - ChildObject 3 - Base Object

If I put a filter on the BaseObject table, will LLBLGen automatically query child tables to determine the type of the object - or will it just assume the object is a "BaseObject" unless I explicitly query the child tables?

Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 03-Jan-2007 10:32:26   

mshe wrote:

Hello,

I'm using the inheritence features in LLBLGen Pro 2.0 using TargetPerEntity (1 entity per table).

I have a table called BaseObject and another table called ChildObject.

ChildObject inherits from BaseObject.

Given a set of PKs, how can I return an entitycollection which contains ChildObjects + BaseObjects?

For example, if my data is like:

1 - Base object 2 - ChildObject 3 - Base Object 4 - Base Object

and I pass in a set of keys: 2,3, I should get back an entityCollection with:

2 - ChildObject 3 - Base Object

If I put a filter on the BaseObject table, will LLBLGen automatically query child tables to determine the type of the object - or will it just assume the object is a "BaseObject" unless I explicitly query the child tables? Thanks.

It will do the polymorphic fetching for you. If you fetch a collection of BaseObject instances, with the filter for 2 and 3, it will fetch 2 and 3 into an instance of the class type they represent, and as ChildObject is-a BaseObject, it will be loaded and you'll get in your collection a ChildObject (2) and a BaseObject (3).

If you fetch a childobject collection (I assume you're using adapter so you have set the factory to ChildObjectEntityFactory), llblgen pro knows which tables to fetch the data from, and as childobject is a subtype, it will only fetch entities of type childobject and subtypes of childobject.

Frans Bouma | Lead developer LLBLGen Pro
mshe
User
Posts: 167
Joined: 02-Feb-2006
# Posted on: 03-Jan-2007 10:51:25   

So just to clarify - if I set my EntityCollection to use a factory of "BaseObject". It will know to check all related tables and fetch the proper subtype?

Wow, that's neat that it knows to fetch all subtypes ... In fact that's perfect smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 03-Jan-2007 11:05:01   

mshe wrote:

So just to clarify - if I set my EntityCollection to use a factory of "BaseObject". It will know to check all related tables and fetch the proper subtype?

Correct simple_smile

Wow, that's neat that it knows to fetch all subtypes ... In fact that's perfect smile

simple_smile

Frans Bouma | Lead developer LLBLGen Pro