public async Task <GetIngredientVm> GetById(int id) { var ingredient = await _ingredientsRepository.GetByIdWithRecipes(id); if (ingredient == null) { throw new NotFoundException($"Ingredient with id: {id} not found"); } var recipes = ingredient.RecipeIngredient.Select(x => x.Recipe).ToList(); var recipesDto = _mapper.Map <List <IngredientRecipeDto> >(recipes); return(new GetIngredientVm { Name = ingredient.Name, Description = ingredient.Description, Recipes = recipesDto }); }