ZEXSM / OData.QueryBuilder

OData.QueryBuilder - library for creating complex OData queries (OData version 4.01) based on data models with linq syntax.
MIT License
72 stars 31 forks source link

Count elements in expand #57

Closed christophanneken closed 3 years ago

christophanneken commented 3 years ago

I want to count the elements of an expand operation e.g.

private Uri _query = new ODataQueryBuilder()
            .For<Customer>("Customer")
            .ByList()
            .Expand(customer =>
            {
                customer.For<LocationOfCustomer>(customer => customer.LocationsOfCustomers)
                    .Top(0)
                    .Count();
            })
            .Count()
            .Top(0)
            .ToUri();

Is there another way to do so or is this feature currently missing

ZEXSM commented 3 years ago

Hey! There is currently no function. I will add it in the near future.

christophanneken commented 3 years ago

Hi, I implemented it by myself. Below the changes I made.

IODataOptionExpand.cs

TODataOption Count(bool value = true);

ODataQueryExpand.cs

public IODataQueryExpand<TEntity> Count(bool value = true)
{
    _stringBuilder.Append($"{ODataOptionNames.Count}{QuerySeparators.EqualSign}{value.ToString().ToLower()}{QuerySeparators.Nested}");

    return this;
}