Reputation: 1
I am learning ASP.NET by examples from the book on C# and that book was written at time when AutoMapper supported the method Initialize. I tried to circumvent it but not successfully. I replaced :
// Mapper.Initialize(
// cfg =>
// {
// cfg.CreateMap<Inventory, Inventory>()
//.ForMember(x => x.Orders, opt => opt.Ignore());
// });
with:
var config = new MapperConfiguration(cfg => cfg.CreateMap<Inventory, Inventory>()
.ForMember(x => x.Orders, opt => opt.Ignore()));
and it seems (at least do not show errors in VS 2019).
But in the following:
// GET: api/Inventory
[HttpGet, Route("")]
public IEnumerable<Inventory> GetInventory()
{
var inventories = _repo.GetAll();
return Mapper.Map<List<Inventory>, List<Inventory>>(inventories);
}
I get an error:
An object reference is required for the non-static field, method, or property 'Mapper.Map<Inventory, Inventory>(Inventory)
Can somebody help me? Thanks. I am a newcomer here. Jiri
Upvotes: 0
Views: 86