HomeActive Query Builder - Query analysis and modificationProgrammatic modification of SQL queriesHow to add object to the query programmatically

2.1. How to add object to the query programmatically

There are four methods that can help you with this:

  • UnionSubQuery.AddObject
  • UnionSubQuery.AddObjectAt
  • UnionSubQuery.AddObjectWithFK
  • UnionSubQuery.AddObjectWithFKAt

Methods with the "At" should be used when dragging objects to the Design Pane as they allow to specify position of the added object.

Methods with the "WithFK" suffix instruct the component to add joins to the newly added object from other objects that may exist in the active sub-query (according to the foreign keys or by identical field names (CreateLinksByIdenticalFieldNamesCreateLinksFromForeignKeys).

The "WithFK"-suffixed methods are obsolete, they will not exist in the upcoming version 3.0. I recommend to use separate methods to add links to existing query objects automatically:

  • UnionSubQuery.AddFKLinksForObject
  • UnionSubQuery.AddIdenticalFieldsLinksForObject

The UnionSubQuery.AddLinkedObjectsFor method allows to link an object with other query objects by foreign keys even if it doesn't direclty linked with existing objects. Intermediate objects will be added to the query automatically (if such objects exist) in order to join this object.


UnionSubQuery usq = queryBuilder1.Query.ActiveUnionSubquery;
DataSource dataSource = usq.AddObject("Orders");
int addedLinksNum = usq.AddFKLinksForObject(dataSource);
if (addedLinksNum == 0) 

This page was: Helpful | Not Helpful