Пример #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);
        }