I have a piece of code that throws exception and I dont quite understand why.
public async Task<List<CategoryVm>> Handle(GetCategoriesListQuery request, CancellationToken cancellationToken)
{
var categories = (await _categoryRepository.ListAllAsync()).OrderBy(x => x.Name);
// var list = categories.ToList();
return _mapper.Map<List<CategoryVm>>(categories);
}
I managed to get around problem as below. Would be be nice know why this works.
public async Task<List<CategoryVm>> Handle(GetCategoriesListQuery request, CancellationToken cancellationToken)
{
var categories = (await _categoryRepository.ListAllAsync()).OrderBy(x => x.Name);
var list = categories.ToList();
return _mapper.Map<List<CategoryVm>>(list);
}
Category and CategoryVm
public class CategoryVm
{
public Guid CategoryId { get; set; }
public string Name { get; set; }
}
public class Category: AuditableEntity
{
public Guid CategoryId { get; set; }
public string Name { get; set; }
public ICollection<Event> Events { get; set; }
}
Aucun commentaire:
Enregistrer un commentaire