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

$root literal #2794

Open
mata007 opened this issue Nov 15, 2023 · 1 comment · May be fixed by #3157
Open

$root literal #2794

mata007 opened this issue Nov 15, 2023 · 1 comment · May be fixed by #3157

Comments

@mata007
Copy link

mata007 commented Nov 15, 2023

Hello,
I wanted to use Microsoft.OData.UriParser.ODataUriParser to parse a URL in which the $root literal was used.

The OData 4.01 specification states the following:

5.1.1.14.5 [$root](https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_root)
The $root literal can be used in expressions to refer to resources of the same service. It can be used as a single-valued expression or within [complex or collection literals](https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_ComplexandCollectionLiterals).

Example 108: all employees with the same last name as employee A1235
http://host/service/Employees?$filter=LastName eq $root/Employees('A1245')/LastName

Example 109: products ordered by a set of customers, where the set of customers is passed as a JSON array containing the resource paths from $root to each customer.
http://host/service/ProductsOrderedBy(Customers=@c)?@c=[$root/Customers('ALFKI'),$root/Customers('BLAUS')]

However, if I used the parser on the example from the specification ( http://host/service/Employees?$filter=LastName eq $root/Employees('A1245')/LastName ), the parser would return the error "Could not find a property named '$root' on type 'Employees'."

I don't know if I'm doing something wrong, or if this literal is not implemented.
And if it's not implemented, I'd like to ask if that's in the plans. Alternatively, if it is possible to solve it somehow at the moment.

@ElizabethOkerio
Copy link
Contributor

@mata007 we currently do not support $root. We welcome a contribution.

xuzhg added a commit that referenced this issue Dec 23, 2024
5.1.1.14.5 $root
The $root literal can be used in expressions to refer to resources of the same service. It can be used as a single-valued expression or within complex or collection literals.

Example 108: all employees with the same last name as employee A1235

http://host/service/Employees?$filter=LastName eq $root/Employees('A1245')/LastName

Example 109: products ordered by a set of customers, where the set of customers is passed as a JSON array containing the resource paths from $root to each customer.

http://host/service/ProductsOrderedBy(Customers=@c)?@c=[$root/Customers('ALFKI'),$root/Customers('BLAUS')]
@xuzhg xuzhg linked a pull request Dec 23, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants