I have this simple DTO class:
public class ActionDTO
{
public int Id { get; set; }
public required string Name { get; set; }
}
And I have this mapping profile:
public class MappingProfiles : Profile
{
public MappingProfiles() {
CreateMap<ActionDTO, Models.Admin.Action>();
CreateMap<Models.Admin.Action, ActionDTO>();
}
}
The controller looks like this:
[HttpGet]
public async Task<ActionResult<IEnumerable<ActionDTO>>> GetActions()
{
if (planProDbContext.Actions == null)
{
return NotFound();
}
IEnumerable<Models.Admin.Action> actions = await planProDbContext.Actions.ToListAsync();
// List<ActionDTO> actionDTOs = mapper.Map<List<ActionDTO>>(actions);
return Ok(actions);
}
As you see, I return actions
, and not a list of dto’s. But the signature of the method is Task<ActionResult<IEnumerable<ActionDTO>>>
. Why does this work?