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

Verify more carefully that property named Count is a collection property

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Blocker - P1 Blocker - P1
    • 2.23.0
    • Affects Version/s: 2.22.0
    • Component/s: None
    • None
    • Fully Compatible
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Summary

      When having a property of type long named Count, the translation of a Linq-query with greater than fails.

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      How to Reproduce

      Test document:

              [BsonIgnoreExtraElements]
              public class TestDoc
              {
                  public long Count { get; set; }
              }

      Code: 

                  var settings = MongoClientSettings.FromConnectionString("mongodb://localhost");
                  settings.LinqProvider = MongoDB.Driver.Linq.LinqProvider.V3;
                  var client = new MongoClient(settings);
                  var db = client.GetDatabase("test");
                  var coll = db.GetCollection<TestDoc>("long_count_fail");
                  var doc = new TestDoc() { Count = 123 };
                  await coll.InsertOneAsync(doc);
                  var countGreaterThanZero = coll.AsQueryable().Where(x => x.Count > 0).ToList();
                  Console.WriteLine(countGreaterThanZero.Count);  // 0 – failure
                  var countEquals123 = coll.AsQueryable().Where(x => x.Count == 123).ToList();
                  Console.WriteLine(countEquals123.Count);  // >= 1 – works

      Additional Background

      In Version 2,20.0 of the driver, the failure could not be observed, a change in v2.22.0 is suspected to cause the error.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            m.wildgruber@sevantage.de Markus Wildgruber
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: