This is the error it gives.
An exception of type 'System.InvalidOperationException' occurred in System.Core.dll but was not handled in user code
Below is my expression that generated the error:
if (refeicoes != null)
{
for (int i = 0; i < refeicoes.Length; i++) {
lista.Add(pesquisaHotel.Where(x => x.SubOfferGroups.Select(a => a.AnswerOffersList[0].IncludesItems).Contains(refeicoes[i])).Select(a=> a.ProductId).First());
lista.Add(pesquisaHotel.Where(x => x.SubOfferGroups.Select(a => a.AnswerOffersList[0].IncludesFoodPlans).Contains(refeicoes[i])).Select(a => a.ProductId).First());
}
pesquisaHotel = pesquisaHotel.Where(x => lista.Contains(x.ProductId)).ToArray();
}
The error appears above the refeicoes
line. This array has a value, which in this case is: "Breakfast for 2"
. Does anyone have a clue to solve this cucumber?
Personally, I discovered that the above loop is wrong. It can not be on top of meals, but on top of Hotel search, as meals will always come with a record. It is mounted with a click on top of the checkbox. I retraced the loop, swapping meals for research. I just did it and now it gives the error like that. When i == 0, it adds to the list. but when i is greater than zero, there it goes, saying "Index out of bounds". How do I solve this? Below the new code. Remembering that in this example, meals have only one record.
if (refeicoes != null)
{
for (int i = 0; i < pesquisaHotel.Length; i++)
{
lista.Add(pesquisaHotel.Where(x => x.SubOfferGroups.Select(a => a.AnswerOffersList[0].IncludesFoodPlans).Contains(refeicoes[i])).Select(a => a.ProductId).FirstOrDefault());
lista.Add(pesquisaHotel.Where(x => x.SubOfferGroups.Select(a => a.AnswerOffersList[0].IncludesItems).Contains(refeicoes[i])).Select(a => a.ProductId).FirstOrDefault());
}
pesquisaHotel = pesquisaHotel.Where(x => lista.Contains(x.ProductId)).ToArray();
}