private void InitializeViewModel(ComparisonOperator model)
        {
            QueryExpressionViewModel query  = this.GetQueryExpressionViewModel(this);
            SelectStatementViewModel select = this.GetSelectStatementViewModel(this);

            if (select == null)
            {
                return;
            }

            if (model.LeftExpression is PropertyReference)
            {
                PropertyReference          property   = (PropertyReference)model.LeftExpression;
                TableExpressionViewModel   tableVM    = select.Tables.Where(t => t.Alias == property.Table.Alias).FirstOrDefault();
                PropertyReferenceViewModel propertyVM = new PropertyReferenceViewModel(this, tableVM, (PropertyReference)model.LeftExpression);

                this.LeftExpression     = propertyVM;
                this.LeftExpressionView = new PropertyReferenceView(propertyVM);
            }
            else if (model.LeftExpression is ParameterExpression)
            {
                if (query != null)
                {
                    ParameterExpression          expression = (ParameterExpression)model.LeftExpression;
                    ParameterExpressionViewModel vm         = query.QueryParameters.Where(p => p.Name == expression.Name).FirstOrDefault();
                    if (vm != null)
                    {
                        this.LeftExpression     = vm.GetParameterReferenceViewModel(this);
                        this.LeftExpressionView = new ParameterReferenceView((ParameterReferenceViewModel)this.LeftExpression);
                    }
                }
            }

            if (model.RightExpression is PropertyReference)
            {
                PropertyReference          property   = (PropertyReference)model.RightExpression;
                TableExpressionViewModel   tableVM    = select.Tables.Where(t => t.Alias == property.Table.Alias).FirstOrDefault();
                PropertyReferenceViewModel propertyVM = new PropertyReferenceViewModel(this, tableVM, (PropertyReference)model.RightExpression);

                this.RightExpression     = propertyVM;
                this.RightExpressionView = new PropertyReferenceView(propertyVM);
            }
            else if (model.RightExpression is ParameterExpression)
            {
                if (query != null)
                {
                    ParameterExpression          expression = (ParameterExpression)model.RightExpression;
                    ParameterExpressionViewModel vm         = query.QueryParameters.Where(p => p.Name == expression.Name).FirstOrDefault();
                    if (vm != null)
                    {
                        this.RightExpression     = vm.GetParameterReferenceViewModel(this);
                        this.RightExpressionView = new ParameterReferenceView((ParameterReferenceViewModel)this.RightExpression);
                    }
                }
            }
        }
 private void IntializeViewModel(PropertyExpression model)
 {
     if (model.Expression == null)
     {
         return;
     }
     if (model.Expression is PropertyReference)
     {
         SelectStatementViewModel parent = this.Parent as SelectStatementViewModel;
         if (parent != null)
         {
             PropertyReference          property   = (PropertyReference)model.Expression;
             TableExpressionViewModel   tableVM    = parent.Tables.Where(t => t.Alias == property.Table.Alias).FirstOrDefault();
             PropertyReferenceViewModel propertyVM = new PropertyReferenceViewModel(this, tableVM, (PropertyReference)model.Expression);
             this.OnExpressionSelected(propertyVM);
         }
     }
 }
        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");
        }
 public PropertyReferenceViewModel(HermesViewModel parent, TableExpressionViewModel table, PropertyReference model) : base(parent, model)
 {
     this.Table = table;
 }