Repository: dotnet/efcore
File: src/EFCore.Cosmos/Query/Internal/CosmosQueryableMethodTranslatingExpressionVisitor.cs (C#)

Code before:
        {
            // For nullable types, we want to return null from Max, Min, and Average, rather than throwing. See Issue #35094.
            // Note that relational databases typically return null, which propagates. Cosmos will instead return no elements,
            // and hence for Cosmos only we need to change no elements into null.
            source = source.UpdateResultCardinality(ResultCardinality.SingleOrDefault);
        }

        var projection = (SqlExpression)selectExpression.GetMappedProjection(new ProjectionMember());
        projection = _sqlExpressionFactory.Function(functionName, [projection], resultType, _typeMappingSource.FindMapping(resultType));

        return AggregateResultShaper(source, projection, resultType);
    }

    private bool TryApplyPredicate(ShapedQueryExpression source, LambdaExpression predicate)
    {
        var select = (SelectExpression)source.QueryExpression;

        if ((select.Limit is not null || select.Offset is not null)
            && !TryPushdownIntoSubquery(select))
        {
            return false;
        }

        if (TranslateLambdaExpression(source, predicate) is { } translation)
        {
            if (translation is not SqlConstantExpression { Value: true } && translation is not SqlUnaryExpression { OperatorType: ExpressionType.Not, Operand: SqlConstantExpression { Value: false } })
            {
                select.ApplyPredicate(translation);
            }

            return true;
        }

        return false;
    }

    private bool TryApplyPredicate(SelectExpression select, SqlExpression predicate)
    {
        if ((select.Limit is not null || select.Offset is not null)
            && !TryPushdownIntoSubquery(select))
        {
            return false;
        }

        select.ApplyPredicate(predicate);
        return true;
    }

    private bool TryApplyOffset(SelectExpression select, SqlExpression offset)
    {
        if ((select.Limit is not null || select.Offset is not null) && !TryPushdownIntoSubquery(select))

Review comment (refactor):
This `if` condition is very long and likely exceeds the repo line-length guideline; please wrap it across multiple lines (and consider extracting the special-case check into a small helper/local to improve readability).
```suggestion
            static bool IsTriviallyTruePredicate(SqlExpression sqlExpression)
                => sqlExpression is SqlConstantExpression { Value: true }
                    || sqlExpression is SqlUnaryExpression
                    {
                        OperatorType: ExpressionType.Not,
                        Operand: SqlConstantExpression { Value: false }
                    };

            if (!IsTriviallyTruePredicate(translation))
```

Code after:
        {
            // For nullable types, we want to return null from Max, Min, and Average, rather than throwing. See Issue #35094.
            // Note that relational databases typically return null, which propagates. Cosmos will instead return no elements,
            // and hence for Cosmos only we need to change no elements into null.
            source = source.UpdateResultCardinality(ResultCardinality.SingleOrDefault);
        }

        var projection = (SqlExpression)selectExpression.GetMappedProjection(new ProjectionMember());
        projection = _sqlExpressionFactory.Function(functionName, [projection], resultType, _typeMappingSource.FindMapping(resultType));

        return AggregateResultShaper(source, projection, resultType);
    }

    private bool TryApplyPredicate(ShapedQueryExpression source, LambdaExpression predicate)
    {
        var select = (SelectExpression)source.QueryExpression;

        if ((select.Limit is not null || select.Offset is not null)
            && !TryPushdownIntoSubquery(select))
        {
            return false;
        }

        if (TranslateLambdaExpression(source, predicate) is { } translation)
        {
            if (translation is not SqlConstantExpression { Value: true })
            {
                select.ApplyPredicate(translation);
            }

            return true;
        }

        return false;
    }

    private bool TryApplyPredicate(SelectExpression select, SqlExpression predicate)
    {
        if ((select.Limit is not null || select.Offset is not null)
            && !TryPushdownIntoSubquery(select))
        {
            return false;
        }

        select.ApplyPredicate(predicate);
        return true;
    }

    private bool TryApplyOffset(SelectExpression select, SqlExpression offset)
    {
        if ((select.Limit is not null || select.Offset is not null) && !TryPushdownIntoSubquery(select))