private void OnAddTable(Entity entity)
        {
            if (this.Model == null)
            {
                SelectStatement select = new SelectStatement(null, entity);
                select.FROM = new List <TableExpression>();
                TableExpression first_table = new TableExpression(select, entity);
                select.FROM.Add(first_table);
                TableExpressionViewModel vm = new TableExpressionViewModel(this, first_table);
                this.Model = select;
                this.Tables.Add(vm);
                this.WhereClause = new BooleanExpressionViewModel(this, "WHERE");
                this.OnPropertyChanged("FromClauseDescription");
                return;
            }

            SelectStatement model = this.Model as SelectStatement;

            if (model.FROM == null)
            {
                model.FROM = new List <TableExpression>();
            }

            if (model.FROM.Count == 0)
            {
                TableExpression table = new TableExpression(model, entity);
                model.FROM.Add(table);
                TableExpressionViewModel tableVM = new TableExpressionViewModel(this, table);
                this.Tables.Add(tableVM);
            }
            else
            {
                JoinExpression join = new JoinExpression(model, entity);
                model.FROM.Add(join);
                // This sequence of JoinExpressionViewModel building is the must !!!
                // Because ON clause may look up for JoinExpressionViewModel in SelectStatement.Tables collection while it is not added there yet =/
                JoinExpressionViewModel joinVM = new JoinExpressionViewModel(this, join);
                this.Tables.Add(joinVM);
                joinVM.Filter = new BooleanExpressionViewModel(joinVM, "ON");
                // JoinExpressionViewModel building sequence end
            }
            this.OnPropertyChanged("FromClauseDescription");
        }
 private void AddTable(TableExpression table)
 {
     if (table is JoinExpression)
     {
         // This sequence of JoinExpressionViewModel building is the must !!!
         // Because ON clause may look up for JoinExpressionViewModel in SelectStatement.Tables collection while it is not added there yet =/
         JoinExpressionViewModel joinVM = new JoinExpressionViewModel(this, table);
         this.Tables.Add(joinVM);
         joinVM.Filter = new BooleanExpressionViewModel(joinVM, "ON");
         // JoinExpressionViewModel building sequence end
     }
     else if (table is SelectStatement)
     {
         this.Tables.Add(new SelectStatementViewModel(this, (SelectStatement)table));
     }
     else
     {
         this.Tables.Add(new TableExpressionViewModel(this, table));
     }
 }