Beispiel #1
0
 public void AddAndCondition(DmlfConditionBase cond)
 {
     if (cond == null)
     {
         return;
     }
     if (Where == null)
     {
         Where = new DmlfWhere();
     }
     if (Where.Condition != null)
     {
         if (Where.Condition is DmlfAndCondition)
         {
             ((DmlfAndCondition)Where.Condition).Conditions.Add(cond);
         }
         else
         {
             var and = new DmlfAndCondition();
             and.Conditions.Add(Where.Condition);
             and.Conditions.Add(cond);
             Where.Condition = and;
         }
     }
     else
     {
         Where.Condition = cond;
     }
 }
        public void CompileFilter()
        {
            if (!Filters.Any()) return;

            var type = DetectFilterType(FilterType, DbshColumns);

            var entity = Entities.First();
            var expr = new DmlfColumnRefExpression
            {
                Column = new DmlfColumnRef
                {
                    ColumnName = entity.GetColumnName(Alias),
                    Source = entity.QuerySource,
                }
            };

            var andCondition = new DmlfAndCondition();

            foreach (var filter in Filters)
            {
                var cond = FilterParser.ParseFilterExpression(type, expr, filter);
                andCondition.Conditions.Add(cond);
            }

            if (andCondition.Conditions.Count == 1)
            {
                FilterCondition = andCondition.Conditions[0];
            }
            else
            {
                FilterCondition = andCondition;
            }
        }
Beispiel #3
0
        protected bool EvalBetween(IDmlfNamespace ns)
        {
            var cond = new DmlfAndCondition();

            cond.Conditions.Add(new DmlfRelationCondition
            {
                LeftExpr  = LowerBound,
                Relation  = "<=",
                RightExpr = Expr,
            });
            cond.Conditions.Add(new DmlfRelationCondition
            {
                LeftExpr  = Expr,
                Relation  = "<=",
                RightExpr = UpperBound,
            });
            return(cond.EvalCondition(ns));
        }
Beispiel #4
0
 public void AddAndCondition(DmlfConditionBase cond)
 {
     if (cond == null) return;
     if (Where == null) Where = new DmlfWhere();
     if (Where.Condition != null)
     {
         if (Where.Condition is DmlfAndCondition)
         {
             ((DmlfAndCondition)Where.Condition).Conditions.Add(cond);
         }
         else
         {
             var and = new DmlfAndCondition();
             and.Conditions.Add(Where.Condition);
             and.Conditions.Add(cond);
             Where.Condition = and;
         }
     }
     else
     {
         Where.Condition = cond;
     }
 }
        private void CreateFilterConditions(DmlfCommandBase cmd)
        {
            foreach(var col in SourceJoinModel.Columns.Values)
            {
                var colFilterCondition = col.FilterCondition;

                // process additional condition
                var additional = _dbsh.AdditionalFilters.FirstOrDefault(x => x.Column == col.Alias);
                if (additional != null)
                {
                    var type = SourceColumnSqlModel.DetectFilterType(additional.FilterType, col.DbshColumns);

                    var entity = col.Entities.First();
                    var expr = new DmlfColumnRefExpression
                    {
                        Column = new DmlfColumnRef
                        {
                            ColumnName = entity.GetColumnName(col.Alias),
                            Source = entity.QuerySource,
                        }
                    };

                    var additionalCondition = FilterParser.ParseFilterExpression(type, expr, additional.Filter);

                    if (colFilterCondition != null)
                    {
                        var andCondition = new DmlfAndCondition();
                        andCondition.Conditions.Add(additionalCondition);
                        andCondition.Conditions.Add(colFilterCondition);
                        colFilterCondition = andCondition;
                    }
                    else
                    {
                        colFilterCondition = additionalCondition;
                    }
                }

                if (colFilterCondition != null)
                {
                    var orCond = new DmlfOrCondition();

                    if (col.Entities.Count == 1)
                    {
                        var entity = col.Entities.Single();
                        if (entity.SingleKeyColumnNameOrAlias != null)
                        {
                            var expr = new DmlfColumnRefExpression
                            {
                                Column = new DmlfColumnRef
                                {
                                    ColumnName = entity.GetColumnName(entity.SingleKeyColumnNameOrAlias),
                                    Source = entity.QuerySource,
                                }
                            };
                            orCond.Conditions.Add(new DmlfIsNullCondition
                            {
                                Expr = expr,
                            });
                        }
                    }

                    if (orCond.Conditions.Any())
                    {
                        orCond.Conditions.Add(colFilterCondition);
                        cmd.AddAndCondition(orCond);
                    }
                    else
                    {
                        cmd.AddAndCondition(colFilterCondition);
                    }
                }
            }
        }