Otis wrote:
Nice suggestion!
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