I have entities that I map with automapper to domain models and return them from the service as Iqueryable. How can I use .Select or use automapper projectTo on them to map them to view models, because when I try I get thrown an error IAsyncEnumerable cannot be used for parameter of type IEnumerable on the navigation property inside the domain model?
class HomeDomainModel
{
public string Id { get; set; }
public ICollection<HumanDomainModel> Humans { get; set; }
}
class HumanDomainModel
{
public string Id { get; set; }
}
class HomaEntity
{
public string Id { get; set; }
public ICollection<HumanEntity> Humans { get; set; }
}
class HumanEntity
{
public string Id { get; set; }
}
// IQueryable<HomeEntity>
var homeEntities = homeEntities.GetAll();
// IQueryable<HomeDomainModel>
var homeDomainModels = humanEntity.ProjectTo<HomeDomainModel>();
// Here it throws the exception
var homeViewModel = homeDomainModels.Select(hdm => new HomeViewModel()
{
Id = hdm.Id,
HumansCount = hdm.Humans.Count()
}).ToArrayAsync();
homeEntities.GetAll();
? Do you want to mapHomaEntity
toHomeViewModel
?