private void attachTable(LogicalQueryTable source, LogicalTable joinWith)
        {
            // check if join can be performed, if not then exception is thrown
            validateAttachArguments(source, joinWith);

            // join tables
            LogicalQueryTable target = new LogicalQueryTable() {Table = joinWith};

            // if the join table is in fact a part of another physical table already included in source logical table
            // then dont join them
            // always join tables if the target table is of entity type
            if (!isJoinRequired (source, target)) {
                target.Alias = source.Alias;
            } else {
                string alias = createTableAlias(joinWith);
                target.Alias = alias;

                PhysicalQueryTable physicalQueryTable = new PhysicalQueryTable() {Table = joinWith.PartOfTable, Alias = alias};
                this.physicalTables.Add (physicalQueryTable);

                this.fromSource = createNewJoin (this.fromSource, source, target);
            }

            this.logicalTables.Add (target);
            this.lastTableAdded = target;
        }
 private void setRootTable(LogicalTable rootTable)
 {
     string alias = createTableAlias(rootTable);
     LogicalQueryTable queryTable = new LogicalQueryTable() {Table = rootTable, Alias = alias};
     PhysicalQueryTable physicalQueryTable = new PhysicalQueryTable() {Table = rootTable.PartOfTable, Alias = alias};
     this.logicalTables.Add (queryTable);
     this.physicalTables.Add (physicalQueryTable);
     this.fromSource = physicalQueryTable.ToTableReference();
     this.lastTableAdded = queryTable;
 }