I just thought I would post this to help people out because I've been asked by a friend how to do it in CodeBreeze. There might be a better way, but I'll post a way I've done it. Let's assume you have a target tag called "Parent" in which you wanted to get a recursive list of parents in relation to a specific business entity.
On my TemplateHelper class code behind file that inherits from CodeBreezeTemplateBase, I implement a property called ParentList and a method
private
List<string> _parentList = null;
public List<string> ParentList
{
get
{
if(_parentList == null)
{
_parentList =
new List<string>();
}
return _parentList;
}
set
{
_parentList = value;
}
}
public void GetParentList(CodeBreeze.Business.BusinessEntity entity, CodeBreeze.Business.Project project)
{
string parent = entity.Tags["Parent"].Value;
if(!String.IsNullOrEmpty(parent))
{
ParentList.Add(parent);
CodeBreeze.Business.BusinessEntity parentEntity = project.BusinessEntities.FindByEntity(parent);
GetParentList(parentEntity, project);
}
}
I pass in the CodeBreeze.Business.Project in the method to access the FindByEntity method which normally gets access by passing in the _ActionTarget which is merely a string.
In the code template, I access the list like so:
<%
GetParentList(entity, _Project);
ParentList.ForEach(
delegate(string
parent)
{ %>
<%= parent %>
<%
});
ParentList =
null
;
There may be a better implementation, but I figure this may help other people.