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

Projections not retrieving expected fields after upgrading to 2.19 driver

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.19.2
    • Affects Version/s: None
    • Component/s: LINQ3
    • None
    • 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

      After upgrading to the 2.19 (and 2.19.1) driver with the LINQ3 provider enabled by default, our expression-based projections are no longer retrieving all of the expected fields. Tested against a standalone 5.0.15 server.

      How to Reproduce

      ConsoleApp1.zip

      The attached example includes the connection string and name of the database as arguments in the launchSettings.json. The relevant part is:

      var filter = Builders<Model>.Filter.Eq(m => m.Id, modelToInsert.Id);
      var foundProjection = await collection.Find(filter)
          .Project(Builders<Model>.Projection.Expression(
              m => new View(m.Id) { }))
          .SingleAsync();

      Specifically, having both constructor parameters and initializer braces (whether we actually assign to any properties or not) prevents the driver from retrieving the fields being passed to the constructor. In this case, the result is that the retrieved object has a null ID property even though we requested the ID field via the expression. Removing the {} after "new View(m.Id)" avoids the issue (though in real code we are retrieving additional properties). Removing the Version property from the View class such that all properties are set via constructor also avoids the issue.

      Additional Background

      We ran into this issue after upgrading to the 2.19 driver, presumably because of the switch to the LINQ3 provider by default. Manually switching back to the LINQ2 provider avoids the issue.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            paul.spangler@ni.com Paul Spangler
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: