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

$expand with count #137

Open
cheng93 opened this issue May 23, 2022 · 3 comments
Open

$expand with count #137

cheng93 opened this issue May 23, 2022 · 3 comments

Comments

@cheng93
Copy link

cheng93 commented May 23, 2022

The [email protected] properties are missing.

In the following sample, there are two examples

  • Using EnableQuery and ProjectTo, this works
  • Using this library, this doesn't work

Sample https://github.com/cheng93/AutoMapper.OData/blob/master/ApiController.cs

http://localhost:5238/odata/categories?$expand=products($count=true)

expected

{
 "@odata.context": "http://localhost:5238/odata/$metadata#categories(Products())",
    "value": [
        {
            "CategoryId": 1,
            "CategoryName": "CategoryOne",
            "[email protected]": 3, <-- visible
            "Products": [
                {
                    "ProductId": 1,
                    "ProductName": "ProductOne"
                },
                {
                    "ProductId": 2,
                    "ProductName": "ProductTwo"
                },
                {
                    "ProductId": 3,
                    "ProductName": "ProductThree"
                }
            ]
        },
        {
            "CategoryId": 2,
            "CategoryName": "CategoryTwo",
            "[email protected]": 2, <-- visible
            "Products": [
                {
                    "ProductId": 4,
                    "ProductName": "ProductFour"
                },
                {
                    "ProductId": 5,
                    "ProductName": "ProductFive"
                }
            ]
        }
    ]
}

actual

{
    "@odata.context": "http://localhost:5238/odata/$metadata#categories(Products())",
    "value": [
        {
            "CategoryId": 1,
            "CategoryName": "CategoryOne",
            "Products": [
                {
                    "ProductId": 1,
                    "ProductName": "ProductOne"
                },
                {
                    "ProductId": 2,
                    "ProductName": "ProductTwo"
                },
                {
                    "ProductId": 3,
                    "ProductName": "ProductThree"
                }
            ]
        },
        {
            "CategoryId": 2,
            "CategoryName": "CategoryTwo",
            "Products": [
                {
                    "ProductId": 4,
                    "ProductName": "ProductFour"
                },
                {
                    "ProductId": 5,
                    "ProductName": "ProductFive"
                }
            ]
        }
    ]
}
@BlaiseD
Copy link
Member

BlaiseD commented May 23, 2022

You are correct - that is not currently supported. There is a CountOption property in the expansion.

At the root level it is being applied by setting a property as implemented here.

Still - Ok to create a PR to return count for expansions if you have a solution.

@NikAtIdeally
Copy link

Hi, any progress with this? Also any chance of supporting filter on expand?
So something like :

api/Entity?$expand=Child($filter=name eq "Bob")

@BlaiseD
Copy link
Member

BlaiseD commented Nov 22, 2023

The tests show examples of filter with expand. Ok to submit a PR on the count feature.

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

No branches or pull requests

3 participants