E-Riz
E-Riz

Reputation: 32905

DocumentDB LINQ query not converting enums correctly

According to this and this, The DocumentDb LINQ provider is supposed to use custom JsonConverters when generating queries that use enums (as far back as version 1.10.0). But we're not seeing that behavior.

My project is referencing Microsoft.Azure.DocumentDb 1.13.1 and we're still seeing a LINQ query that converts an enum to its numeric value. A Where() predicate like this

request => request.Source == sourceId && request.State == state

generates a query like this

{SELECT * FROM root WHERE ((root["Source"] = "5c196602-1a60-406a-81cd-1be5ac23eb18") AND (root["State"] = 0))) }

State is an enum and is correctly serialized/stored in the DB as its string value, per our serializer settings on the docdb client object. This is not a problem with serializing/deserializing the objects to/from documents - that works as expected.

What might we be doing wrong? Is it documented somewhere how to enable/utilize this capability? Do we have to register the JSON converters with the LINQ provider or something?

Upvotes: 0

Views: 775

Answers (1)

Nick Chapsas
Nick Chapsas

Reputation: 7200

1.13.1 is a version with query serialisation issues so it is a bug with the SDK.

Those issues where fixed after 1.19.1 as you can see here: https://learn.microsoft.com/en-us/azure/cosmos-db/sql-api-sdk-dotnet#a-name11911191

  • Fixed a bug in which the custom JsonSerializer settings were not being honored for some queries and stored procedure execution

You will have to upgrade to a post 1.19.1 version of the SDK.

Upvotes: 1

Related Questions