Skip to content
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

Fix for Error occurs when you check whether a string or integer literal is in an enum collection #3023

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Microsoft.OData.Core/UriParser/Binders/InBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,27 @@ internal QueryNode BindInOperator(InToken inToken, BindingState state)
inToken.Right, new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetUntyped())), state.Model);
}

if (ShouldConvertLeftOperand(left, right))
{
left = MetadataBindingUtils.ConvertToTypeIfNeeded(left, right.ItemType);
}

return new InNode(left, right);
}

/// <summary>
/// Checks if the left operand is either an integral or a string type and the right operand is a collection of enums.
/// </summary>
/// <param name="leftNode">The left operand.</param>
/// <param name="rightNode">The right operand.</param>
/// <returns>True if the condition is met, otherwise false.</returns>
private static bool ShouldConvertLeftOperand(SingleValueNode leftNode, CollectionNode rightNode)
WanjohiSammy marked this conversation as resolved.
Show resolved Hide resolved
{
// If the left operand is either an integral or a string type and the right operand is a collection of enums,
// Calls the MetadataBindingUtils.ConvertToTypeIfNeeded() method to convert the left operand to the same enum type as the right operand.
return (rightNode is CollectionPropertyAccessNode && rightNode.ItemType.IsEnum()) && (leftNode.TypeReference.IsString() || leftNode.TypeReference.IsIntegral());
}

/// <summary>
/// Retrieve SingleValueNode bound with given query token.
/// </summary>
Expand Down
Loading