Hello guys,
I'm looking for a way to filter an entity collection "step-by-step".
Please have a look at the following code first:
//STEP 1
public PvAssistantsCollection GetAllAssistants()
{
//Get all assistants stored in the database
PvAssistantsCollection result = new PvAssistantsCollection();
result.GetMulti(null);
return result;
}
//STEP 2 uses STEP 1 as input
public PvAssistantsCollection GetEnabledAssistants()
{
//Get all assistants which are enabled
PvAssistantsCollection result = GetAllAssistants();
PredicateExpression filterResult = new PredicateExpression();
filterResult.AddWithAnd(PvAssistantsFields.Ass_Is_Enabled == true);
result.GetMulti(filterResult);
return result;
}
//STEP 3 uses STEP 2 as input
public PvAssistantsCollection GetTopLevelAssistants()
{
//Get all assistants that have no parent
PvAssistantsCollection result = GetEnabledAssistants();
PredicateExpression filterResult = new PredicateExpression();
filterResult.AddWithAnd(PvAssistantsFields.Ass_Parent_Id == DBNull.Value);
result.GetMulti(filterResult);
return result; <--- those results came out wrong in my testings
}
As you will see, I try to have separate access to different aggregation levels of my "assistants". Sometimes I want to see all my assistants available, sometimes just the top level assistants and so on. The scenarios are unlimited.
In order to reduce and reuse code, I was hoping I could narrow down the wanted results by a step-by-step approach. However, it doesn't work. The results of "GetTopLevelAssistants()" are often not correct.
It seems as if I can't use an already filtered EntityCollection as the starting point of a new filtering. At least not in the way I'm doing it here.
Could anybody please help me with some good advice?
By the way: This code related posting refers to my former question on the suggested architecture for such an approach: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=14631
Thank you very much,
Ingmar