Pass a parent entity property to a child

Posts   
 
    
LloydM
User
Posts: 17
Joined: 05-Dec-2007
# Posted on: 25-Mar-2008 02:00:35   

Here's my dilemma:

I have an LLBLGen person child entity with an age property that I previously computed via a simple function based on the person's birthdate and current date in the person entity. I'm using the Self Servicing template, so I called the age calc function in the person entity's OnFetch override method.

I just found out that the child entity's age needs to be based on a date stored in an entity two levels above it but see no good way to pass the date down from the top level entity. I could reference the property like this: personEntity.middleEntity.topEntity.dateProperty, but it requires all the referenced objects to be re-fetched from the database for each child entity.

The Adapter template may have been a better approach here, but it's a little late for me to switch now.

Perhaps I could hook into another event to set a class level date variable defined in the person entity?

Any help would be greatly appreciated.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 25-Mar-2008 03:54:16   

Hi LloydM,

I don't get if you have an inheritance scenario here or just want to retrieve a property through some related entities. Anyway, if the related entities are already fetched they wont perform an extra fetch (in the standard configuration).

David Elizondo | LLBLGen Support Team
LloydM
User
Posts: 17
Joined: 05-Dec-2007
# Posted on: 25-Mar-2008 14:48:00   

David,

I am attempting to retrieve a related parent entity property. I'm not sure what you mean by "standard configuration", but I have confirmed through sql profiler that a fetch of the grand parent\parent entities is occuring on every call to the age function in the child person entity.

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 25-Mar-2008 20:05:50   

You could use a prefetch path to obtain the whole graph in the initial fetch. Please see: Using the generated code - SelfServicing - Prefetch Paths