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

Nullable Enums not supported

    • Type: Icon: Bug Bug
    • Resolution: Gone away
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.10.2
    • Component/s: Read Operations
    • None
    • Environment:
      Windows 10 Pro Bld 18363

      It seems like the C# driver is unable to work with Nullable Enums when I expose the IQueryable of the Collection to Microsoft's OData libraries.  I've tried it with both EnumRepresentationConvention(BSonType.String) as well as BSonType.Int32.

       

      Here is what I'm trying to achieve:

      1. Create API document using Swagger.
      2. Generate the controller and models using Swagger Codegen
      3. Adjust the controller code to support .NET Core 3.1 (Models are left alone).
      4. Add OData support to Startup.cs and controller ([EnableQuery()] and exposing of IQueryable<MyObject>)
      5. Try to query using query string "$filter=MyEnumFld eq 'enumvalue'"

       

      The above create an error of "InvalidOperationException. (Convert({Document}

      {MyEnumField}

      Nullable`1) == 2".

      Because swagger code gen marks all Enums as nullable (to support PATCHing use-cases I assume), this above error occurs.  When I remove the nullable (question mark) from the model, everything works.

      I'd really like the models to not be touched so that they can be regenerated from a shared swagger doc at any time in the future.

       

            Assignee:
            dmitry.lukyanov@mongodb.com Dmitry Lukyanov (Inactive)
            Reporter:
            mkoziel@gmail.com Mike Koziel
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: