Пример #1
0
        protected virtual SelectExpression TranslateSelectExpression(LinqCommand cmd, TranslationContext context)
        {
            if (cmd.SelectExpression != null) //special case for Md1, Select is provided in command
            {
                context.CurrentSelect = cmd.SelectExpression;
                return(cmd.SelectExpression);
            }
            var linqExpr         = cmd.Lambda.Body;
            var exprChain        = ExpressionChain.Build(linqExpr);
            var tableExpr        = _translator.ExtractFirstTable(exprChain[0], context);
            var selectExpression = _translator.Analyze(exprChain, tableExpr, context);
            // Check expected type - it will be used for final result conversion if query returns a single value (like Count() query)
            var resultType = exprChain[exprChain.Count - 1].Type;

            if (resultType.IsGenericQueryable())
            {
                resultType = selectExpression.Type;
            }
            _translator.BuildSelectResultReaderAndCutOutSql(selectExpression, context, resultType);

            BuildOffsetsAndLimits(context);
            // then prepare Parts for SQL translation
            CheckTablesAlias(context);
            CheckColumnNamesAliases(context);
            cmd.SelectExpression = context.CurrentSelect;
            return(context.CurrentSelect);
        }
Пример #2
0
        protected virtual SelectExpression TranslateSelectExpression(Expression linqExpr, TranslationContext context)
        {
            var exprChain        = ExpressionChain.Build(linqExpr);
            var tableExpr        = _translator.ExtractFirstTable(exprChain[0], context);
            var selectExpression = _translator.Analyze(exprChain, tableExpr, context);
            // Check expected type - it will be used for final result conversion if query returns a single value (like Count() query)
            var resultType = exprChain[exprChain.Count - 1].Type;

            if (resultType.IsGenericQueryable())
            {
                resultType = selectExpression.Type;
            }
            _translator.BuildSelectResultReaderAndCutOutSql(selectExpression, context, resultType);

            BuildOffsetsAndLimits(context);
            // then prepare Parts for SQL translation
            CheckTablesAlias(context);
            CheckColumnNamesAliases(context);
            return(context.CurrentSelect);
        }