[CSHARP-948] Take() in Where().OrderBy().Take().Any() not working. Created: 07/Apr/14  Updated: 20/Jan/16  Resolved: 27/Apr/15

Status: Closed
Project: C# Driver
Component/s: Linq
Affects Version/s: 1.8.3
Fix Version/s: 2.1

Type: Bug Priority: Minor - P4
Reporter: Ruslan Sologub Assignee: Craig Wilson
Resolution: Done Votes: 1
Labels: driver
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Both MongoDB and consumer app run on Windows 7 x64


Epic Link: Rewrite Linq

 Description   

I found a quite specific case, when
Where().OrderBy().Take().Any()
does not work as expected, while Where().OrderBy().Take().AsEnumerable().Any()
gives the correct result. Find below the code example:

var repository = new MongoRepository();

var id = new Guid("08d12048-7851-bc17-259f-9b16589f0d15");
const string Username = "testu";
var queryable = repository.database.GetCollection<Machine>("machine").AsQueryable();
var userMachines = queryable.Where(m => m.Username == Username).OrderBy(m => m.CreatedOn);
var mustBeTrue = userMachines.Take(3).Any(m => m.Id == id) == userMachines.Take(3).AsEnumerable().Any(m => m.Id == id);
Console.WriteLine(mustBeTrue)
-------
Prints "False". repository.database is of type MongoDatabase. CreatedOn is DateTime.



 Comments   
Comment by Githook User [ 26/Apr/15 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-948: added support for Any at the root.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/88294d4414d11c93aab8ace3fc401388ebaa69fe

Comment by Craig Wilson [ 07/Apr/14 ]

Hi Ruslan,

Took me a while to figure this out (although I haven't reproduced). If this is NOT throwing an error, then the bug is that it should be. This particular query isn't currently possible in MongoDB using the query engine because you have 2 predicates, one before a Take() and one after. This will be possible after CSHARP-601 is completed.

I'm going to assign a fixVersion of 3.0 and lump it in with the other Linq tickets that are dependent on CSHARP-601.

Thanks for the report.

Generated at Wed Feb 07 21:38:16 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.