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);
                    }
                }
            }
        }
示例#2
0
        private void AddNewParameter()
        {
            QueryExpression model = this.Model as QueryExpression;

            if (model.Parameters == null)
            {
                model.Parameters = new List <ParameterExpression>();
            }

            ParameterExpression parameter = new ParameterExpression(model);

            model.Parameters.Add(parameter);
            parameter.Name = "Parameter" + model.Parameters.Count.ToString();

            ParameterExpressionViewModel childVM = new ParameterExpressionViewModel(this, parameter);

            this.QueryParameters.Add(childVM);
        }
示例#3
0
 public ParameterExpressionView(ParameterExpressionViewModel viewModel) : this()
 {
     this.DataContext = viewModel;
 }