Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-948

Take() in Where().OrderBy().Take().Any() not working.

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.1
    • Affects Version/s: 1.8.3
    • Component/s: LINQ
    • Environment:
      Both MongoDB and consumer app run on Windows 7 x64
    • None
    • None
    • None
    • None
    • None
    • None

      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.

            Assignee:
            craig.wilson@mongodb.com Craig Wilson
            Reporter:
            sologub Ruslan Sologub
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: