-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Array of Enums not working for Filtering #536
Comments
Isn't that because the function only accepts strings and not enums? |
PR #439 apparently fixes it but is pending on a test case being created. |
@SantoshPabba Does a cast function call work for you?
By the way, what do you want to return? Return myshifts only its workingDays contains 'Monday'? if yes, why don't use 'eq'? as or you also can use 'in' operator: I haven't found a chance to test the aboves. Let me know if none of them doesn't work. |
Hi @dweeden, I have already used In my case, I have an array of enums in one property and trying to filter the result based on 1 value that matches the query. I am looking for a Shifts endpoint, which contains "Monday" as one of the working days. It should return all days pertaining to a shift ID, but the day should match the filter. |
Hi @xuzhg , Thanks for the reply, I tried the first 2 queries but got an empty result and the next two were throwing 500 errors. |
@xuzhg @SantoshPabba I have tried the options as well. The first two options proposed by @xuzhg, where there's an explicit cast to
However, when I used the fully qualified enum as follows, it returns the correct result:
In the example above, Also, when I use
returned: {
"@odata.context": "http://localhost:64771/v1/$metadata#Shifts",
"value": [
{
"Id": 1,
"Name": "Shift 1",
"WorkingDays": [
"Monday",
"Tuesday",
"Thursday"
]
},
{
"Id": 3,
"Name": "Shift 3",
"WorkingDays": [
"Monday",
"Friday",
"Thursday"
]
}
]
} @SantoshPabba could you share the error message you got? @xuzhg is the fact that
|
I've found that the reason there's an error when using For binary operators, the internal QueryNode BindBinaryOperator(BinaryOperatorToken binaryOperatorToken)
{
ExceptionUtils.CheckArgumentNotNull(binaryOperatorToken, "binaryOperatorToken");
SingleValueNode left = this.GetOperandFromToken(binaryOperatorToken.OperatorKind, binaryOperatorToken.Left);
SingleValueNode right = this.GetOperandFromToken(binaryOperatorToken.OperatorKind, binaryOperatorToken.Right);
IEdmTypeReference typeReference;
this.resolver.PromoteBinaryOperandTypes(binaryOperatorToken.OperatorKind, ref left, ref right, out typeReference);
return new BinaryOperatorNode(binaryOperatorToken.OperatorKind, left, right, typeReference);
} The Maybe we should report this a bug or feature gap in ODL and have it fixed there. |
@habbes Yes. It's a gap/bug as I mentioned that EnumAsStringResolver is not applied to In operator parser. Please file an issue in the ODL side to track on it. |
@SantoshPabba another approach you could consider is to store the enums as flags instead of a collection of enums and use the Here's how you would define the enum: [Flags]
public enum WorkingDay
{
None = 0;
Monday = 1;
Tuesday = 2;
Wednesday = 4;
Thursday = 8;
Friday = 16;
// etc. keep doubling to ensure each value has its own bit position
} Then in your entity, define a single-value field instead of a collection:
And here's how you would set the field values: Shift shift = new Shift
{
Name = "Shift 1",
WorkingDays = WorkingDay.Monday | WorkingDay.Wednesday | WorkingDay.Friday
// ...
} And here's what your query would look like
|
Hi @habbes Thanks for your response. I tried both the syntaxes you suggested and working as expected. I might miss something in the second syntax while trying for the first time ( @xuzhg suggestion). Working Syntaxes:
Thanks to @habbes, @xuzhg and others for your extended support in resolving my issue. |
@habbes I'd suggest pluralizing your enum name in that sample, since having flag enums be plural is a best practice enforced by static analysis I'd also probably recommend either using binary literals or bit shifted left ints as the values for maintainability, but that one is a lot more subjective. |
Hi Everyone,
I was trying to filter the result using the OData filter, in which one of the columns contains a List of Enums (i.e. Days of the week). But it is throwing the OData error like below.
response JSON example :
"name": "Shift 1", "status": "Approved", "workingDays": [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" ], "id": 1
url:
odata/myshifts?$filter=workingDays/any(t:contains(t,'Monday'))
Resonse
"message": "No function signature for the function with name 'contains' matches the specified arguments. The function signatures considered are: contains(Edm.String Nullable=true, Edm.String Nullable=true)."
The text was updated successfully, but these errors were encountered: