0

¡Hi! I need help for this problem. When I do a request the result give me is IEnumerable. I need to convert this IEnumerable to List. This code resolve my problem but i'm looking for another alternative for resolve my problem more elegant than this.

   var folderCategoriesIds = FolderRepository.GetAll().Where(c => folderIds.Any(y => y == c.Id)).Select(x => x.Categories.Select(y => y.Id)).ToList();
   List<int> list = new List<int>();
   foreach (var item in folderCategoriesIds)
   {
       list.AddRange(item.ToList());
   }

enter image description here

Stella Esparza
  • 101
  • 1
  • 9

1 Answers1

2

You can use SelectMany to flatten lists. Just add .SelectMany(x => x) before ToList() and it will work

JL0PD
  • 3,698
  • 2
  • 15
  • 23