AutoMapper / AutoMapper.Extensions.OData

Creates LINQ expressions from ODataQueryOptions and executes the query.
MIT License
140 stars 38 forks source link

$filter not working when using with $expand #103

Closed ederwii closed 3 years ago

ederwii commented 3 years ago

Hi,

I have an OData endpoint working with this extension, but somehow the $filter on expanded properties seems to not be working

This is my implementation in the backend

        public async Task<IActionResult> Get([FromODataUri] Guid key, ODataQueryOptions<DTO> options)
        {
             var result = await _context.Entity.Where(x => x.Id == key).GetAsync(_mapper, options, new QuerySettings() { });
             return Ok(result.FirstOrDefault());
        }

Everything seems to be working fine, the problem is when trying to filter an expanded property, ie:

curl --location --request GET 'http://localhost:50460/odata/Controller(00000000-0000-0000-0000-000000000000)?$expand=Collection($filter=Field eq '\''value'\'')' \

The ($filter=Field eq '\''value'\'')' seems to not be working. Am I missing something?

I have an OData endpoint that is working with the data entity directly and this filter is working fine, so nothing to check on the OData implementation.

Something to mention is that both DTO and Entity classes are pretty much identical, no special config needed.

BlaiseD commented 3 years ago

GetQueryAsync supports filtering child collections - examples here.

GetAsync does not since it depends on the Map as opposed to ProjectTo for GetQueryAsync. PRs are welcome.

ederwii commented 3 years ago

@BlaiseD I'm not able to expand properties using GetQueryAsync (expanded properties are just not in the response), And the implementation is pretty much the same

public async Task<IActionResult> Get([FromODataUri] Guid key, ODataQueryOptions<DTO> options)
{
     var result = await _context.Entity.Where(x => x.Id == key).GetQueryAsync(_mapper, options, new QuerySettings() { });
     return Ok(result.FirstOrDefault());
}