We are creating the Web.Api application of the angularjs application. Web.Api returns json result.
Step one received the data:
public List<DataItem>> GetData()
{
return Mapper.Map<List<DataItem>>(dataRepository.GetData());
}
It worked like a charm. Then we made async repo data, and we changed the code to work with it.
public List<DataItem>> GetData()
{
return Mapper.Map<List<DataItem>>(dataRepository.GetDataAsync().Result);
}
No problems. Now we wanted to make my Web.Api complete async awayt, so we changed it to:
public async Task<List<DataItem>> GetData()
{
return await Mapper.Map<Task<List<DataItem>>>(dataRepository.GetDataAsync());
}
At this point, Automapper gets confused. First, we had the following mapping rule: Mapper.CreateMap ();
This worked until the async web api method overflowed. An exception indicated that a card from
Task<ICollection<Data>> to Task<ICollection<DataItem>>.
The converter has been changed to
Mapper.CreateMap<Task<List<Data>>, Task<List<DataItem>>>();
When checking the configuration, he complains that the result cannot be matched. How should we configure mappings?