Map async result with automapper

前端 未结 3 555
夕颜
夕颜 2021-02-01 07:14

We are createing a Web.Api application of a angularjs application. The Web.Api returns a json result.

Step one was getting the data:

    public List

        
3条回答
  •  自闭症患者
    2021-02-01 07:34

    You need to move the async data fetch out of the Map call:

    var data = await dataRepository.GetDataAsync();
    return Mapper.Map>(data);
    

    Alternatively, you can use AutoMapper LINQ projections:

    var data = await dbContext.Data.ProjectTo().ToListAsync();
    

    I don't know if your repository exposes IQueryable directly (we don't use repositories). Our apps use the second version pretty much exclusively these days.

提交回复
热议问题