I have the following classes
public PhoneModel
{
int PhoneID;
string PhoneType;
string PhoneNumber;
}
public ContactModel
{
int ContactID;
string FirstName;
string LastName;
List<PhoneModel> PhoneNumber;
}
I need to display a list of contacts with all phone numbers of each contacts.
var contactList = await ContactBLL.GetContactList();
IEnumerable<ContactViewModel> contacts = contactList.ToList().ConvertAll(
async c => new ContactViewModel
{
phones = (await ContactBLL.GetContactPhones(c.ContactID)).ToList(),
firstName = c.FirstName,
lastName = c.LastName
});
I am currently getting the compilation error saying "cannot implicitly convert type 'System.Threading.Tasks.Task.List to IEnumerable...." However, without the async call to get the phone list, it will work (of course without the phones). I can change the async function GetContactPhones() to sync function and it will work as expected. My question is there a way to make the code above work with async call?
Thank you.