HomeActive Query Builder - Query analysis and modificationProgrammatic modification of SQL queriesHow to define aliases programmatically

2.5. How to define aliases programmatically

The following example adds aliases for the fields of the main query in case an alternate name is defined for a field and alias is empty.

UnionSubQuery unionSubQuery = queryBuilder1.Query.FirstSelect();

unionSubQuery.BeginUpdate();

try
{
    for (int i = 0; i < unionSubQuery.CriteriaList.Count; i++)
    {
        CriteriaItem ci = unionSubQuery.CriteriaList[i];

        if (ci.ExpressionField != null) // the criteria item is bound to a metadata field
        {
            if (ci.AliasString.Length == 0 && ci.ExpressionField.AltName.Length > 0)
            {
                ci.AliasString = ci.ExpressionField.AltName;
            }
        }
    }
}
finally
{
    unionSubQuery.EndUpdate();
}

This page was: Helpful | Not Helpful