AutoMapper / AutoMapper.Extensions.OData

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

OData filtration in expand section not works #44

Closed tonynuke closed 4 years ago

tonynuke commented 4 years ago

Hi! I use odata filter in expand section https://localhost:44333/odata/employees?$expand=Contacts($filter=Value eq 'value'). Expected I expect that filtration will be executed in odata request and response data will be filtered. Actual Filtration in expand section does not work. Response data is unfiltered. Without mapping extensions response data is filtered.

Details AutoMapper.AspNetCore.OData.EFCore 2.0.0 Microsoft.AspNetCore.OData 7.4.1 AutoMapper 10.0.0 .NET Core 3.1 Microsoft.EntityFrameworkCore 3.1.6

Code More code details in repository https://github.com/tonynuke/ContactsWebApp

public class EmployeesController : ControllerBase
    {
        private readonly EmployeeDbContext dbContext;
        private readonly IMapper mapper;

        [HttpGet]
        public Task<IQueryable<EmployeeDTO>> Get(ODataQueryOptions<EmployeeDTO> options)
        {
            var request = this.dbContext.Employees.AsNoTracking();
            return request.GetQueryAsync(this.mapper, options);
        }
}
 public class MappingProfile : Profile
    {
        public MappingProfile()
        {
            CreateMap<global::Employee.Domain.Contacts.Contact, ContactDTO>();

            CreateMap<global::Employee.Domain.Employee, EmployeeDTO>()
                .ForMember(nameof(EmployeeDTO.Name), opt => opt.MapFrom(c => c.Name.Value));
        }
    }
BlaiseD commented 4 years ago

Please send us a sample we can just build and run. Your sample includes npm.

Also include an example of the endpoint which works without the the extensions.

tonynuke commented 4 years ago

Here is extracted code sample: https://github.com/tonynuke/OdataAutomapper

BlaiseD commented 4 years ago

You're correct. We'll leave this open until there's a fix. PRs are welcome.

BlaiseD commented 4 years ago

This should be working in 2.0.1-preview.0. Test cases are here.