我正在我的asp.net webapi项目中实现automapper。我还在业务层中实现了异步任务。我基本上想要返回MoviesDto对象而不是Movie实体,但是获取错误列表不包含getAwaiter的定义。错误在行
return await _mapper.Map<List<MoviesDto>>(movies);
不确定问题是什么。这是我的代码
MoviesDto
public class MoviesDto : BaseDto
{
public int MovieID { get; set; }
public string Title { get; set; }
public int? ReleaseYear { get; set; }
public string Plot { get; set; }
public int? MovieLength { get; set; }
}
业务访问层
public class MovieBusiness: IMovieBusiness
{
IMovieService _movieService;
IMapper _mapper;
public MovieBusiness(IMovieService movieService, IMapper mapper)
{
_movieService = movieService;
_mapper = mapper;
}
public async Task<IEnumerable<MoviesDto>> GetAllMovies()
{
var movies = _movieService.GetMovies();
return await _mapper.Map<List<MoviesDto>>(movies);
}
}
答案 0 :(得分:0)
方法_mapper.Map()
不是异步的,因此您不必await
。
只需使用return _mapper.Map<List<MoviesDto>>(movies);