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

Adding a condition to cast QueryNode to SingleResourceCastNode for Unquoted Type Parameter #1313

Merged
merged 14 commits into from
Oct 30, 2024

Conversation

WanjohiSammy
Copy link
Contributor

Issues

This pull request fixes #1304.

Description

This modification adds a condition to cast QueryNode to SingleResourceCastNode.

Currently, the QueryNode is only converted to ConstantNode and supports the cast function only with quoted type parameters. For unquoted type parameters, the QueryNode will be of type SingleResourceCastNode, resulting in an error because SingleResourceCastNode cannot be cast to ConstantNode.

For example, given the following entities:

namespace NS;

public class Person
{
    public int Id { get; set; }
    public string FullName { get; set; }
    public MyAddress Location { get; set; }
}

public class Employee : Person
{
    public string EmployeeNumber { get; set; }
}

public class MyAddress
{
    public string Street { get; set; }
}

public class WorkAddress : MyAddress
{
    public string OfficeNumber { get; set; }
}

With this change, we should be able to support these casts with unquoted type parameters:

  • cast(NS.Employee): cast Person to Employee
  • cast(Location, NS.WorkAddress): cast Location property to NS.WorkAddress

The following are currently supported :

  • cast('NS.Employee'): Quoted Employee type
  • cast(Location, 'NS.WorkAddress'): Quoted WorkAddress type

Checklist (Uncheck if it is not completed)

  • Test cases added
  • Build and test with one-click build and test script passed

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.

@WanjohiSammy WanjohiSammy requested review from xuzhg, habbes, mikepizzo and gathogojr and removed request for mikepizzo September 13, 2024 15:32
@WanjohiSammy WanjohiSammy marked this pull request as draft September 13, 2024 15:33
@WanjohiSammy WanjohiSammy force-pushed the fix/1304-missing-cast-singleresourcenode branch from eeb83f5 to 3d27793 Compare September 13, 2024 16:01
@WanjohiSammy WanjohiSammy marked this pull request as ready for review September 13, 2024 16:03
xuzhg
xuzhg previously approved these changes Oct 3, 2024
@xuzhg
Copy link
Member

xuzhg commented Oct 3, 2024

left comments and approve for others.

Copy link
Contributor

@habbes habbes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to see a test with an actual "unquoted" type parameter in a cast expression in the query options of a URL. Or is that already handled elsewhere?

@WanjohiSammy
Copy link
Contributor Author

WanjohiSammy commented Oct 9, 2024

It would be good to see a test with an actual "unquoted" type parameter in a cast expression in the query options of a URL. Or is that already handled elsewhere?

Currently, odata.net does not know how to handle "unquoted" type parameter in a cast expression as outlined in this issue #1744 . In this limitation, it is not possible to write E2E tests. However, in this PR, I have added unit tests.

gathogojr
gathogojr previously approved these changes Oct 30, 2024
@WanjohiSammy WanjohiSammy merged commit a5eb631 into main Oct 30, 2024
1 check passed
WanjohiSammy added a commit that referenced this pull request Oct 30, 2024
…r Unquoted Type Parameter (#1313)

* Cast queryNode to SingleResourceCastNode as well
* Added tests for both ConstantNode and SingleResourceCastNode
@WanjohiSammy WanjohiSammy deleted the fix/1304-missing-cast-singleresourcenode branch November 13, 2024 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing Cast to SingleResourceCastNode in BindSingleResourceCastFunctionCall Method in QueryBinder
4 participants