[CSHARP-3020] Nullable Enums not supported Created: 23/Mar/20  Updated: 27/Oct/23  Resolved: 04/May/20

Status: Closed
Project: C# Driver
Component/s: Read Operations
Affects Version/s: 2.10.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Mike Koziel Assignee: Dmitry Lukyanov (Inactive)
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 10 Pro Bld 18363



 Description   

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.

 



 Comments   
Comment by Dmitry Lukyanov (Inactive) [ 13/Apr/20 ]

Hello mkoziel@gmail.com, can you please provide the following:
1. the structure of `MyObject` and nested objects if they are presented.
2. the way how you configure this option `EnumRepresentationConvention`.
3. The full error message.
4. It will be great if you can try to reproduce this situation without OData with c# driver itself (let me know if you need help with it) and then provide a repro.

Generated at Wed Feb 07 21:44:08 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.