Skip to content

Commit 18d204a

Browse files
committed
CSHARP-1773: fix issue with using sample after another pipeline stage.
1 parent dc02987 commit 18d204a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/MongoDB.Driver/Linq/MongoQueryable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ public static IMongoQueryable<TSource> Sample<TSource>(this IMongoQueryable<TSou
843843
Expression.Call(
844844
null,
845845
GetMethodInfo(Sample, source, count),
846-
source.Expression,
846+
Expression.Convert(source.Expression, typeof(IMongoQueryable<TSource>)),
847847
Expression.Constant(count)));
848848
}
849849

tests/MongoDB.Driver.Tests/Linq/MongoQueryableTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,18 @@ public void Sample()
876876
"{ $sample: { size: 100 } }");
877877
}
878878

879+
[SkippableFact]
880+
public void Sample_after_another_function()
881+
{
882+
RequireServer.Check().VersionGreaterThanOrEqualTo("3.2.0");
883+
var query = CreateQuery().Select(x => x.A).Sample(100);
884+
885+
Assert(query,
886+
2,
887+
"{ $project: { A: '$A', _id: 0 } }",
888+
"{ $sample: { size: 100 } }");
889+
}
890+
879891
[Fact]
880892
public void Select_identity()
881893
{

0 commit comments

Comments
 (0)