Skip to content

Commit

Permalink
OrderBy fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
object committed Apr 20, 2012
1 parent d8fe6eb commit 69e31f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 8 additions & 0 deletions Mongo.Context.Tests/QueryTests.cs
Expand Up @@ -180,6 +180,7 @@ public void FilterGreaterRating()
var result = ctx.Products.FindAll(ctx.Products.Rating > 3).ToList();
Assert.AreEqual(2, result.Count);
}

[Test]
public void FilterNameLength()
{
Expand All @@ -194,6 +195,13 @@ public void FilterGreaterIDAndNameLength()
Assert.AreEqual(2, result.Count);
}

[Test]
public void FilterNameLengthOrderByCountVerifyResult()
{
var result = ctx.Products.FindAll(ctx.Products.Name.Length() == 4).OrderBy(ctx.Products.Rating).Count();
Assert.AreEqual(2, result, "The count is not correctly computed.");
}

[Test]
public void ProjectionVerifyExcluded()
{
Expand Down
5 changes: 2 additions & 3 deletions Mongo.Context/Queryable/QueryExpressionVisitor.cs
Expand Up @@ -42,11 +42,10 @@ public override Expression VisitMethodCall(MethodCallExpression m)
if (m.Method.Name == "OrderBy" || m.Method.Name == "OrderByDescending")
{
var lambda = Visit(ReplaceFieldLambda(m.Arguments[1]));
var method = ReplaceGenericMethodType(m.Method, (lambda as LambdaExpression).ReturnType);

return Visit(Expression.Call(
method,
this.queryableCollection.Expression,
ReplaceGenericMethodType(m.Method, (lambda as LambdaExpression).ReturnType),
Visit(m.Arguments[0]),
lambda));
}
else
Expand Down

0 comments on commit 69e31f0

Please sign in to comment.