It's a little bit hard to answer your question in full without a little more information.
However, what you are talking about is certainly possible. It becomes more complex as the number of related entities becomes more complex, or if there are different starting points.
The easiest path would be to just include ALL the relations. But I assume that this would be too inefficient, otherwise you wouldn't have asked the question.
I also assume that you are only returning fields from the main (starting point) entity? Otherwise you need all the relations anyway. You said that the resultset was always the same.
So, assuming you have a static starting point of one entity, as you've said, and a number of possible relations to it, you could do something like (pseudocode!):
//Assuming you have three entities:
//EntityMain
//EntityRelated1
//EntityRelated2
bool requiresRelation1 = false;
bool requiresRelation2 = false;
//any time a predicate is used on a related entity, set that entity flag to true
if (txtFieldAOnEntityRelated1 != "")
{
//create and add the predicate here
requiresRelation1 = true;
}
if (txtFieldBOnEntityRelated1 != "")
{
//create and add the predicate here
requiresRelation1 = true;
}
if (txtFieldAOnEntityRelated2 != "")
{
//create and add the predicate here
requiresRelation2 = true;
}
if (requiresRelation1)
{//create relation to EntityRelated1 here}
if (requiresRelation2)
{//create relation to EntityRelated2 here}
I hope that helps. It's possible I'm not understanding the question completely.
I'm from Chicago too--where in Chicago are you from?