Skip to content

Commit 568398c

Browse files
committed
CSHARP1257: First and Last rewriting was ignoring the predicate argument.
1 parent f4b7fb1 commit 568398c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/MongoDB.Driver.Tests/Linq/Translators/AggregateProjectionTranslatorTests_Group.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ public async Task Should_translate_last_with_normalization()
176176
result.Value.B.Should().Be("Balloon");
177177
}
178178

179+
[Test]
180+
public void Should_throw_an_exception_when_last_is_used_with_a_predicate()
181+
{
182+
Func<Task> act = () => Group(x => x.A, g => new { g.Last(x => x.A == "bin").B });
183+
184+
act.ShouldThrow<NotSupportedException>();
185+
}
186+
179187
[Test]
180188
public async Task Should_translate_max_with_embedded_projector()
181189
{

src/MongoDB.Driver/Linq/Processors/GroupSerializationInfoBinder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ protected override Expression VisitMember(MemberExpression node)
220220

221221
// we are going to rewrite g.Last().Member to g.Select(x => x.Member).Last()
222222
var call = currentNode as MethodCallExpression;
223-
if (call != null && IsAggregateMethod(call.Method.Name))
223+
if (call != null && IsAggregateMethod(call.Method.Name) && call.Arguments.Count == 1)
224224
{
225225
var source = Visit(call.Arguments[0]);
226226
var typeArguments = call.Method.GetGenericArguments();

0 commit comments

Comments
 (0)