OData / odata.net

ODataLib: Open Data Protocol - .NET Libraries and Frameworks
https://docs.microsoft.com/odata
Other
686 stars 349 forks source link

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

Closed WanjohiSammy closed 1 month ago

WanjohiSammy commented 2 months ago

Issues

This pull request fixes #2371.

Description

This change is to fix the issue raised where the in operator does not allow using a string or integer literal as left operand when comparing against a collection of enums.

The change involves:

Assume you have the following entity:

public class Employee 
{
    public int Id { get; set; }
    public string Name { get; set; }
    public List<WeekDay> WorkingDays { get; set; }
}

public enum WeekDay
{
    Monday = 1,
    Tuesday = 2,
    Wednesday = 3,
    Thursday = 4,
    Friday = 5,
    Saturday = 6,
    Sunday = 7
}

This change enables support of the following scenarios for $filter with In Operator:

// left operand without fully qualified namespace
/Employees?$filter='Monday' in WorkingDays

// left operand with integral value in single quotes
/Employees?$filter='1' in WorkingDays

// left operand with integral value without single quotes
/Employees?$filter=1 in WorkingDays

Checklist (Uncheck if it is not completed)

Additional work necessary

If documentation update is needed, please add "Docs Needed" label to the issue and provide details about the required document change in the issue.

ElizabethOkerio commented 1 month ago

// left operand with fully qualified namespace /Employees?$filter=Fully.Qualified.Namespace'Monday' in WorkingDays

// left operand without fully qualified namespace /Employees?$filter='Monday' in WorkingDays

// left operand with integral value in single quotes /Employees?$filter='1' in WorkingDays

// left operand with integral value without single quotes /Employees?$filter=1 in WorkingDays

From the issue description, the first and last scenarios are currently supported..is that true? What this PR is supporting is the second and third scenario?

WanjohiSammy commented 1 month ago

// left operand with fully qualified namespace /Employees?$filter=Fully.Qualified.Namespace'Monday' in WorkingDays

// left operand without fully qualified namespace /Employees?$filter='Monday' in WorkingDays

// left operand with integral value in single quotes /Employees?$filter='1' in WorkingDays

// left operand with integral value without single quotes /Employees?$filter=1 in WorkingDays

From the issue description, the first and last scenarios are currently supported..is that true? What this PR is supporting is the second and third scenario?

@ElizabethOkerio Currently, we are supporting only the 1st scenario. This PR is to support 2nd, 3rd and 4th scenarios. I have edited the description.