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

Support type cast in group by #1182

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

clemvnt
Copy link

@clemvnt clemvnt commented Mar 2, 2024

Hello,

Cast type support in group by.

This PR needs OData/odata.net#2879.

Issues

#1180

Description

For the following group by : groupby((MyAddress/Fully.Qualified.Namespace.HomeAddress/HomeNO))

The response was an error :

System.NotSupportedException: The query specified in the URI is not valid. Binding OData QueryNode of kind 'SingleResourceCast' is not supported by 'AggregationBinder'.

Now, the response is :

[
  {
    "myAddress": {
        "homeNO": "Value1"
    }
  },
  {
    "myAddress": {
        "homeNO": "Value2"
    }
  }
]

@clemvnt clemvnt marked this pull request as draft March 2, 2024 00:46
@clemvnt
Copy link
Author

clemvnt commented Mar 2, 2024

@microsoft-github-policy-service agree

IEdmStructuredTypeReference structured = node.StructuredTypeReference;
Contract.Assert(structured != null, "NS casts can contain only structured types");

Type clrType = Model.GetClrType(structured);

Choose a reason for hiding this comment

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

Could we stick with using var for consistency ?

Copy link
Author

Choose a reason for hiding this comment

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

This method is based on the following method :

public virtual Expression BindSingleResourceCastNode(SingleResourceCastNode node, QueryBinderContext context)
{
CheckArgumentNull(node, context);
IEdmStructuredTypeReference structured = node.StructuredTypeReference;
Contract.Assert(structured != null, "NS casts can contain only structured types");
Type clrType = context.Model.GetClrType(structured);
Expression source = BindCastSourceNode(node.Source, context);
return Expression.TypeAs(source, clrType);
}

There doesn't seem to be any consistency between explicit types and var in the project.

But if someone of the organization feels the same way, I'll make the changes.


Type clrType = Model.GetClrType(structured);

Expression source = Bind(node.Source);

Choose a reason for hiding this comment

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

Could we stick with using var for consistency ?

Copy link
Author

Choose a reason for hiding this comment

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

See previous comment.

{
List<Product> productList = new List<Product>();

Product p1 = new DerivedProduct

Choose a reason for hiding this comment

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

Could we stick with using var for consistency ?

Copy link
Author

Choose a reason for hiding this comment

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

See previous comment.

@@ -1584,6 +1720,22 @@ public IQueryable<Customer> Get()
return _customers.AsQueryable();
}
}

public class ProductsForTypeCastController : ODataController

Choose a reason for hiding this comment

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

Could we document these public classes and methods ?

Copy link
Author

Choose a reason for hiding this comment

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

Here, we're in a test file, so the other classes in this file have no comments.

But if someone of the organization feels the same way, I'll make the changes.

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.

None yet

2 participants