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

Filter builder Where method with nullable Enum value doesn't render correctly

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.4.2
    • Fix Version/s: 2.4.3
    • Component/s: API, Linq
    • Labels:
      None
    • Backwards Compatibility:
      Minor Change
    • Sprint:
      C# Sprint 49

      Description

      When a non-nullable enum field is compared to a nullable value the filter does not render correctly.

      To reproduce use these types:

      public enum E { A, B }
       
      public class C
      {
          public int Id { get; set; }
          [BsonRepresentation(BsonType.String)]
          public E E { get; set; }
      }
      

      And this code:

      var builder = Builders<C>.Filter;
      var value = (E?)E.A;
      var filter = builder.Where(x => x.E == value);
      var registry = BsonSerializer.SerializerRegistry;
      var serializer = registry.GetSerializer<C>();
      var rendered = filter.Render(serializer, registry).ToJson();
      

      The filter renders as:

      "{ \"E\" : 0 }"
      

      but should have rendered as:

      "{ \"E\" : \"A\" }"
      

      because the underlying field serializer uses String representation.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              rstam Robert Stam
              Reporter:
              rstam Robert Stam
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: