-3
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.

Progman
  • 16,827
  • 6
  • 33
  • 48
Eli
  • 3
  • 1
  • 2
    The `Mapper.Map()` method isn't static (anymore), you have to create and configure a mapping and use it then. See https://docs.automapper.org/en/stable/Getting-started.html – Progman Aug 15 '22 at 19:22

1 Answers1

2

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);
lee-m
  • 2,269
  • 17
  • 29