azure-cosmos-dotnet-v3: Custom serializer breaks query
We are continuously addressing and improving the SDK, if possible, make sure the problem persist in the latest SDK version.
Describe the bug The options exposed for the built-in serializer are limited only to changing the name. Additional changes requires a custom serializer. However, any modifications in the custom serializer are not used when performing a query, making the option mostly useless.
To Reproduce
- Implement a custom serializer using example code.
- Store data
- Try to query the data with expression or LINQ
Example data:
enum CustomerRole {
Customer,
Manager
}
record Customer(string Id, string Name, CustomerRole Role);
var results = (await _container.GetItemLinqQueryable<Customer>().Where(x => x.Role == CustomerRole.Customer)).ToList();
Generated document (with custom serializer):
{
"name": "John Doe"
"role": "Customer",
"id": "..."
}
Expected behavior
The generated SQL should follow the settings on the custom serializer, i.e.:
WHERE c.role == "Customer"
The results variable should contain the customer element.
Actual behavior
The generated SQL follows the default serializer and returns wrong name and value, i.e.:
WHERE c.Role == 0
The results variable is always empty.
Environment summary SDK Version: 3.28 OS Version: any
Additional context An additional problem is that when setting a default serializer as in the example, it is not possible to also set the SerializerOptions, so all queries will fail unless each instantiated query also has specific serializer options set. This happens in the linked example as well, because the naming convention is changed.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (9 by maintainers)
#3406 was reverted by #3749 because of a regression. This issue should be reopened.
@jackbond Should be included in the next release, yes.
@YipingRuan
this workaround to not work - I do not believe there are any workaroundsThis workaround works if placing the StringEnumConverter on the enum itself
In the definition
Yields this sql
@neildsh @ealsur Does anyone work on this SDK anymore? It feels quite neglected… at the very least the PMs need to focus more on fixing the SDK they have rather than adding new features