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 with a complex property defined on the derived type in groupby #1408

Open
gathogojr opened this issue Feb 6, 2025 · 0 comments
Labels
bug Something isn't working P3

Comments

@gathogojr
Copy link
Contributor

Assemblies affected

  • Microsoft.AspNetCore.OData 8.x
  • Microsoft.AspNetCore.OData 9.x

Describe the bug
Grouping by a nested property of a derived type does not return the expected results. Scenario uncovered here

Reproduce steps
Use the following code for a simple OData service to repro the issue

// Data models
namespace Microsoft.AspNetCore.OData.E2E.Tests.DollarApply
{   
    public class MyCustomer
    {
        public int Id { get; set; }
        public MyAddress Address { get; set; }
    }

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

    public class MyHomeAddress : MyAddress
    {
        public MyCity City { get; set; } // Complex property
    }

    public class MyCity
    {
        public string Name { get; set; }
    }
}


// Edm model
var builder = new ODataConventionModelBuilder();
            
builder.EntitySet<MyCustomer>("MyCustomers");
builder.ComplexType<MyAddress>();
builder.ComplexType<MyHomeAddress>();
builder.ComplexType<MyCity>();

var model = builder.GetEdmModel();


// Controller
public class MyCustomersController : ODataController
{
    private static readonly List<MyCustomer> myCustomers = new List<MyCustomer>
    {
        new MyCustomer
        {
            Id = 1,
            Address = new MyHomeAddress { Street = "High Street", City = new MyCity { Name = "Belfast" } }
        },
        new MyCustomer
        {
            Id = 2,
            Address = new MyHomeAddress { Street = "Moore Street", City = new MyCity { Name = "Dublin" } }
        }
    };

    [EnableQuery]
    public ActionResult<IEnumerable<MyCustomer>> Get()
    {
        return myCustomers;
    }
}

Data Model
Shared in the "Reproduce steps" section

EDM (CSDL) Model
Shared in the "Reproduce steps" section

Request/Response
Request:

GET http://localhost/MyCustomers?$apply=groupby((Address/Microsoft.AspNetCore.OData.E2E.Tests.DollarApply.MyHomeAddress/City/Name))

Response:

{"value":[{"Address":{}},{"Address":{}}]}

Expected behavior
The following response should be returned:

{"value":[{"Address":{"City":{"Name":"Belfast"}}},{"Address":{"City":{"Name":"Dublin"}}}]}
@gathogojr gathogojr added the bug Something isn't working label Feb 6, 2025
@habbes habbes added the P3 label Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P3
Projects
None yet
Development

No branches or pull requests

2 participants