I have issues with DTO mapping. I'm using OData WebAPI and I need to use IQueryable due to paging, sorting, filtering... When I use this code (simplified for this purpose) in my WebAPI controller, it works
return Ok(_dataService.GetEntities(idUser).Select(e => new EntityDTO
{
ID = e.ID,
Name = e.Name
}));
but when I have separate method for DTO mapping it does not work.
return Ok(_dataService.GetEntities(idUser).Select(e => _dataService.MapToEntityDTO(e)));
Methods in my _dataService object (simplified)
public IQueryable<Entity> GetEntities(long idUser)
{
return from z in _context.Entities select z;
}
public EntityDTO MapToEntityDTO(Entity entity) {
return new EntityDTO {
ID = entity.ID,
Name = entity.Name
};
}
Could you please someone explain me what is wrong with that ? Thanks for help.