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

Not partially evaluating FieldDefinitions

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.0.2, 2.1
    • Affects Version/s: 2.0
    • Component/s: Linq
    • Labels:
      None

      Certain FieldDefinition expressions don't work, such as

      var index = 1;
      Builders<Person>.Update.Inc(x => x..Pets[index].Age, 1);
      

      This will break because we have a member binding to a display class as opposed to a constant where index exists. If you are using a constant instead of a variable as an index, then there isn't a problem.

      Workaround

      Instead of using a lambda expression, you can use a string.

      var index = 1;
      var fieldName = string.Format("Pets.{0}.Age", index);
      Builders<Person>.Update.Inc(fieldName, 1);
      

      *Note that any members that have been mapped to alternate names will still get mapped. This just lacks refactoring support.

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

              Created:
              Updated:
              Resolved: