0

I want to write this part of code but have correct error How to change this

model.RoomGuests.Select(a => 
{
  List<KeyValuePair<string, string>> queryString = new List<KeyValuePair<string, string>>()
  {
      new KeyValuePair<string, string>("city_id",model.ProviderCityCode),
      new KeyValuePair<string, string>("check_in",model.CheckInDate.ToShortDateString()),
      new KeyValuePair<string, string>("check_out",model.CheckOutDate.ToShortDateString()),
      new KeyValuePair<string, string>("adults_count" , a.AdultCount.ToString())
  };
  for (int i = 0; i < a.ChildAge.Length; i++)
      queryString.Add(new KeyValuePair<string, string>($"children[{i}]", a.ChildAge[i].ToString()));
  return httpServiceCaller.CustomGetMethod<BaseResponse<List<Suggestion>>>(ConstData.HelperUrl.suggestion, queryString);
}).Select(a => await a.value)// this error await 

My target from this waiting for get result

pinkfloydx33
  • 11,863
  • 3
  • 46
  • 63
Arian Jira
  • 11
  • 4

1 Answers1

0

I think its a good place to do Task.WhenAll

public async Task Run() {
var results = await Task.WhenAll(model.RoomGuests.Select(a => 
{
  List<KeyValuePair<string, string>> queryString = new List<KeyValuePair<string, string>> 
 ()
  {
      new KeyValuePair<string, string>("city_id",model.ProviderCityCode),
      new KeyValuePair<string, string>("check_in",model.CheckInDate.ToShortDateString()),
      new KeyValuePair<string, string> 
 ("check_out",model.CheckOutDate.ToShortDateString()),
      new KeyValuePair<string, string>("adults_count" , a.AdultCount.ToString())
  };
  for (int i = 0; i < a.ChildAge.Length; i++)
      queryString.Add(new KeyValuePair<string, string>($"children[{i}]", 
  a.ChildAge[i].ToString()));
    return httpServiceCaller.CustomGetMethod<BaseResponse<List<Suggestion>>> 
 (ConstData.HelperUrl.suggestion, queryString);
  }))
}
Józef Podlecki
  • 10,453
  • 5
  • 24
  • 50