Foreach RelatedEntity

Posts   
 
    
rsmith666
User
Posts: 3
Joined: 22-Sep-2005
# Posted on: 09-Dec-2009 01:15:50   

Is there a way to loop through all of the related entities of an entity in one ForEach loop?

I'm trying to write a template (TDL) which generates a method that accepts a boolean value for each RelatedEntity of an entity.

For instance:

public void UsePrefetch( bool prefetchRelation1, bool prefetchRelation2, ... )

As far as I can tell <[Foreach RelatedEntity>] requires an RelationType which means I cannot always generate a comma where I need one if I have to specify each RelationType

Example: public void UsePrefetch(<[ Foreach RelatedEntity OneToMany Comma ]> bool prefetch<[MappedFieldNameRelation]><[ NextForeach ]><[ Foreach RelatedEntity OneToMany Comma ]> bool prefetch<[MappedFieldNameRelation]><[ NextForeach ]> etc.

I won't get a comma in between loops if I need one. RON

rsmith666
User
Posts: 3
Joined: 22-Sep-2005
# Posted on: 09-Dec-2009 01:19:09   

In my example the second Foreach loop should have been another Relationtype

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 09-Dec-2009 06:28:15   

You could do a <[Foreach EntityRelation Separator]> You also could consider use LPT system instead of the normal template system which give you more flexibility.

Please post the final code you want to achieve, maybe we can help you there...

David Elizondo | LLBLGen Support Team
rsmith666
User
Posts: 3
Joined: 22-Sep-2005
# Posted on: 09-Dec-2009 18:13:37   

daelmo wrote:

You could do a <[Foreach EntityRelation Separator]>

That only works on TypedLists (according to the documentation). I got it to work, albeit with a really convoluted set of statements. LPT is the way to go I think, just haven't tackled that yet.

Thanks! This will create a comma delimited list of all the relations and insert the text as specified: <[ Foreach RelatedEntity ManyToMany Comma ]> bool prefetch<[MappedFieldNameRelation]><[ NextForeach ]><[If HasRelation ManyToOne]><[If HasRelation ManyToMany]>, <[ EndIf ]><[ Foreach RelatedEntity ManyToOne Comma ]> bool prefetch<[MappedFieldNameRelation]><[ NextForeach ]><[ EndIf ]><[If HasRelation OneToMany]><[If HasRelation ManyToOne]>, <[ Else ]><[If HasRelation ManyToMany]>, <[ EndIf ]><[ EndIf ]><[ Foreach RelatedEntity OneToMany Comma ]> bool prefetch<[MappedFieldNameRelation]><[ NextForeach ]><[ EndIf ]><[If HasRelation OneToOne]><[If HasRelation OneToMany]>, <[ Else ]><[If HasRelation ManyToOne]>, <[ Else ]><[If HasRelation ManyToMany]>, <[ EndIf ]><[ EndIf ]><[ EndIf ]><[ Foreach RelatedEntity OneToOne Comma ]> bool prefetch<[MappedFieldNameRelation]><[ NextForeach ]><[ EndIf ]>

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 10-Dec-2009 02:45:07   

Yes, the template system have basic functionality, so next time, lpt is best for this cases. Good you got it working.

David Elizondo | LLBLGen Support Team