Prefetch Path Enhancement Question

Posts   
 
    
Wade
User
Posts: 76
Joined: 15-Jun-2004
# Posted on: 15-Nov-2005 18:06:02   

Frans,

Would it be possible to add to the Entity generated code public properties that a developer could just set to use a prefetch path that is available for the basics.

Example:

CustomerEntity - has an Orders Collection and an Address Collection

I would like to get all 3 for my GetMulti()

CustomerEntity cust = new CustomerEntity();

/* Exposed Properties for Prefetch */
cust.UseOrdersPrefetch = true;
cust.UseAddressPrefetch = true;

cust.GetMulti("CHOPS");

Something like that. It seems to me it would be easier from a development side and less code.

What do you think?

Thanks!

swallace
User
Posts: 648
Joined: 18-Aug-2003
# Posted on: 15-Nov-2005 18:47:46   

In terms of syntax that's a good idea, though there's sure getting to be quite a few functions off the Entity objects. simple_smile

Of course, it doesn't allow for the advanced features of prefetch paths like sorting and filtering, but it sure is easy. Just turning them on is what I do 90% of the time anyway.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 15-Nov-2005 19:01:25   

Nice suggestion! simple_smile

The only drawback I see is that if you want to fetch a prefetch path with multiple nodes in the path (Customer - Orders - OrderDetails), you've to fall back to the normal code, but the disadvantage of that is that you have to start over from scratch with the fetch, i.e. it will look totally different.

I'll try if I can cook up a template suggestion tomorrow.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 17-Nov-2005 09:57:16   

Otis wrote:

Nice suggestion! simple_smile

The only drawback I see is that if you want to fetch a prefetch path with multiple nodes in the path (Customer - Orders - OrderDetails), you've to fall back to the normal code, but the disadvantage of that is that you have to start over from scratch with the fetch, i.e. it will look totally different.

I'll try if I can cook up a template suggestion tomorrow.

Ok, basicly it's this: (in an include template, bound to Custom_EntityCollectionTemplate )

for each m:n relation and for each 1:n relation create a boolean private field and a get/set property which sets the private field. Something like:


<[Foreach RelatedEntity OneToMany CrLf]><[If Not MappedFieldRelationIsHidden]>
private bool _use<[MappedFieldNameRelation]>Prefetch = false;

public bool Use<[MappedFieldNameRelation]>Prefetch
{
    get { return _use<[MappedFieldNameRelation]>Prefetch; }
    set { _use<[MappedFieldNameRelation]>Prefetch = value; }
}<[EndIf]><[NextForeach]>

<[Foreach RelatedEntity ManyToMany CrLf]><[If Not MappedFieldRelationIsHidden]>
private bool _use<[MappedFieldNameRelation]>Prefetch = false;

public bool Use<[MappedFieldNameRelation]>Prefetch
{
    get { return _use<[MappedFieldNameRelation]>Prefetch; }
    set { _use<[MappedFieldNameRelation]>Prefetch = value; }
}<[EndIf]><[NextForeach]>

// override GetMulti and build the prefetch path.

you can also add this to the normal entity, then you don't have to override GetMulti, just add GetMulti (I'd pick another name) and call FetchUsingPK(...). Check entityInclude.template for template ideas

Frans Bouma | Lead developer LLBLGen Pro
Wade
User
Posts: 76
Joined: 15-Jun-2004
# Posted on: 18-Nov-2005 04:22:50   

So, does this mean you are adding it to the base templates?

sunglasses sunglasses

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 18-Nov-2005 11:34:03   

No. simple_smile The main reason is that it creates an inconsistency for using the code. You have to rewrite everything if you want to add a subpath, which IMHO is not what it should be. And you can add it yourself pretty easily. I also want to trim down the amount of code generated to a bare minimum and make it easier for users to add their own additional code/features if they want it.

Frans Bouma | Lead developer LLBLGen Pro