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

Not partially evaluating FieldDefinitions

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.0.2, 2.1
    • Component/s: Linq
    • Labels:
      None
    • Sprint:
      C# Sprint 21

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              craiggwilson Craig Wilson
              Reporter:
              craiggwilson Craig Wilson
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: