azure-cosmos-dotnet-v3: LINQ with Contains and Enum does not consider converterType
Describe the bug azure-cosmos-dotnet-v3 supports LINQ query generation. When working with enum serialized as string in simple where clause, the expression is properly translated in SQL using the string value of the enum. But when using Contains operator to generate “IN” clause. This does not work with array of enum, as the SQL translated from it always contains ordinal values of enum, regardless of the model definition.
To Reproduce
public class Foo
{
[JsonProperty("status")]
[JsonConverter(typeof(StringEnumConverter))]
public FooStatus Status { get; set; }
}
public enum FooStatus
{
StatusA,
StatusB
}
var query = container.GetItemLinqQueryable<Foo>();
query = query.Where(foo => new[]{FooStatus.StatusA}.Contains(foo.Status));
Console.WriteLine(query.ToQueryDefinition().QueryText);
Expected behavior
SELECT VALUE root FROM root WHERE (root["status"] IN ("StatusA"))
Actual behavior
SELECT VALUE root FROM root WHERE (root["status"] IN (1))
Environment summary SDK Version: 3.6.0 OS Version (e.g. Windows, Linux, MacOSX):
Operating System: Ubuntu 19.10
Kernel: Linux 5.3.0-40-generic
Architecture: x86-64
Additional context Simple where clause works just as expected
var query = container.GetItemLinqQueryable<Foo>();
query = query.Where(foo => foo.Status == FooStatus.StatusA);
Console.WriteLine(query.ToQueryDefinition().QueryText);
SELECT VALUE root FROM root WHERE (root["status"] = "StatusA")
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 9
- Comments: 18 (8 by maintainers)
@Maya-Painter thank you for merging the fix. We have tested our code with the nighly build and it fixes our problem with quering againts array of enums marked with
JSonConverter(XYZ).Do you know when we can expect next preview package available on the nuget feed?
@lukasz-pyrzyk We do not have a release scheduled yet but are hoping to get it out by the end of the month.