public async Task<List<ViewTACInputsRepositoryDTO>> GetViewTACInputsRepositoryDTO()
{
var items = await _context.ViewTACInputsRepositoryModel.ToListAsync();
var result = AutoMapper.Mapper.Map<List<ViewTACInputsRepositoryDTO>>(items);
return result;
}
An object reference is required for the non-static field, method, or property 'Mapper.Map<List>(object)'
How can I fix this error.
In order to call Map
, you need an instance of IMapper
which comes from a MapperConfiguration
instance where you tell AutoMapper what types it needs to handle.
Something like this:
var config = new MapperConfiguration(cfg => cfg.CreateMap<<List<ViewTACInputsRepositoryDTO>, <List<ViewTACInputsRepositoryDTO>>());
var mapper = config.CreateMapper();
//Now you can do this
result = mapper.Map<List<ViewTACInputsRepositoryDTO>>(items);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.