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

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

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.4.3
    • Affects Version/s: 2.4.2
    • Component/s: API, Linq
    • None
    • Minor Change

      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.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            robert@mongodb.com Robert Stam
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: