Ejemplo n.º 1
0
        public override void Translate(
            MethodCallExpression m, TranslationState state, UniqueNameGenerator nameGenerator)
        {
            // there may not be a preidcate in any method call
            IDbObject condition = null;

            if (m.GetArguments().Any())
            {
                condition = state.ResultStack.Pop();
            }

            var childSelect = (IDbSelect)state.ResultStack.Pop();
            var dbSelect    = (IDbSelect)state.ResultStack.Peek();

            childSelect.Where = condition.ToBinary(_dbFactory);

            var dbJoin = dbSelect.Joins.Single(j => ReferenceEquals(j.To.Referee, childSelect));

            IDbBinary whereClause = null;

            // ReSharper disable once LoopCanBeConvertedToQuery
            foreach (var joinKey in dbJoin.Condition.GetOperands().OfType <IDbColumn>().Where(c => ReferenceEquals(c.Ref, dbJoin.To)))
            {
                var pkColumn = _dbFactory.BuildColumn(dbJoin.To, joinKey.Name, joinKey.ValType.DotNetType, joinKey.Alias);
                var binary   = _dbFactory.BuildBinary(pkColumn, DbOperator.IsNot, _dbFactory.BuildConstant(null));

                whereClause = whereClause.UpdateBinary(binary, _dbFactory);
            }

            state.ResultStack.Push(whereClause);
        }
Ejemplo n.º 2
0
        protected static IDbSelectable GetAggregationTarget(MethodCallExpression m, TranslationState state)
        {
            if (!m.GetArguments().Any())
            {
                return(null);
            }

            var dbObj = state.ResultStack.Pop();

            return((IDbSelectable)dbObj);
        }
Ejemplo n.º 3
0
        private IDbObject BuildCondition(MethodCallExpression m, TranslationState state)
        {
            var countOne = _dbFactory.BuildConstant(1);

            if (!m.GetArguments().Any())
            {
                return(countOne);
            }

            var dbElement = state.ResultStack.Pop();
            var dbBinary  = dbElement.ToBinary(_dbFactory);

            var tuple = Tuple.Create <IDbBinary, IDbObject>(dbBinary, countOne);

            return(_dbFactory.BuildCondition(new [] { tuple }, _dbFactory.BuildConstant(null)));
        }
Ejemplo n.º 4
0
        protected override Expression VisitMethodCall(MethodCallExpression m)
        {
            var caller = m.GetCaller();
            var args   = m.GetArguments();

            Visit(caller);

            // remove unneed DbReference from stack, this is a side effect of translation of the caller
            // we need to translate the caller to have the required select on the stack
            // but we dont neeed other thing that come with it, such as the DbReference
            while (_state.ResultStack.Count > 0 && _state.ResultStack.Peek() is DbReference)
            {
                _state.ResultStack.Pop();
            }

            VistMethodArguments(args);

            if (!_plugIns.TranslateMethodCall(m, _state, _nameGenerator))
            {
                throw new NotSupportedException();
            }

            return(m);
        }