public static IDbSelectable[] ProcessSelection(IDbObject dbObj, IDbObjectFactory factory)
        {
            var dbList = dbObj as IDbList <DbKeyValue>;

            if (dbList != null)
            {
                var keyVals = dbList;
                return(keyVals.SelectMany(kv => ProcessSelection(kv, factory)).ToArray());
            }

            var obj = dbObj as DbReference;

            if (obj != null)
            {
                var dbRef = obj;
                return(new IDbSelectable[] { factory.BuildRefColumn(dbRef, dbRef.RefColumnAlias) });
            }

            var dbBinary = dbObj as IDbBinary;

            if (dbBinary != null && (
                    dbBinary.Operator == DbOperator.Equal ||
                    dbBinary.Operator == DbOperator.NotEqual ||
                    dbBinary.Operator == DbOperator.GreaterThan ||
                    dbBinary.Operator == DbOperator.GreaterThanOrEqual ||
                    dbBinary.Operator == DbOperator.LessThan ||
                    dbBinary.Operator == DbOperator.LessThanOrEqual ||
                    dbBinary.Operator == DbOperator.Is ||
                    dbBinary.Operator == DbOperator.IsNot))
            {
                var dbTrue = factory.BuildConstant(true);
                var tuple  = Tuple.Create <IDbBinary, IDbObject>(dbBinary, dbTrue);
                return(new IDbSelectable[] { factory.BuildCondition(new [] { tuple }, factory.BuildConstant(false)) });
            }

            var keyValue = dbObj as DbKeyValue;

            if (keyValue == null)
            {
                return new[] { (IDbSelectable)dbObj }
            }
            ;

            var selectables = ProcessSelection(keyValue.Value, factory);

            foreach (var selectable in selectables)
            {
                selectable.Alias = keyValue.Key;
            }

            return(selectables);
        }
Esempio n. 2
0
        public static IDbSelectable[] ProcessSelection(IDbObject dbObj, IDbObjectFactory factory)
        {
            switch (dbObj)
            {
            case IDbList <DbKeyValue> dbList:
                var keyVals = dbList;
                return(keyVals.SelectMany(kv => ProcessSelection(kv, factory)).ToArray());

            case DbReference obj:
                var dbRef = obj;
                return(new IDbSelectable[] { factory.BuildRefColumn(dbRef, dbRef.RefColumnAlias) });

            case IDbBinary dbBinary when(
                    dbBinary.Operator == DbOperator.Equal ||
                    dbBinary.Operator == DbOperator.NotEqual ||
                    dbBinary.Operator == DbOperator.GreaterThan ||
                    dbBinary.Operator == DbOperator.GreaterThanOrEqual ||
                    dbBinary.Operator == DbOperator.LessThan ||
                    dbBinary.Operator == DbOperator.LessThanOrEqual ||
                    dbBinary.Operator == DbOperator.Is ||
                    dbBinary.Operator == DbOperator.IsNot):
                var dbTrue = factory.BuildConstant(true);

                var tuple = Tuple.Create <IDbBinary, IDbObject>(dbBinary, dbTrue);
                return(new IDbSelectable[] { factory.BuildCondition(new [] { tuple }, factory.BuildConstant(false)) });
            }

            if (!(dbObj is DbKeyValue keyValue))
            {
                return new[] { (IDbSelectable)dbObj }
            }
            ;

            var selectables = ProcessSelection(keyValue.Value, factory);

            foreach (var selectable in selectables)
            {
                selectable.Alias = keyValue.Key;
            }

            return(selectables);
        }