I am new to async programming. FirstOrDefaultAsync
is throwing an error
List does not contain a definition for FirstOrDefaultAsync()
Can someone explain me what I am doing wrong?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
namespace PatientManagement.Models
{
public class PatientService : IPatientService
{
private List<Patient> patients;
public PatientService()
{
patients = new List<Patient>()
{
new Patient(){ ID = 1, Name = "Akash", Email = "aakash1027@gmail.com" },
new Patient(){ ID = 2, Name = "John", Email = "John@gmail.com" },
new Patient(){ ID = 3, Name = "Mike", Email = "Mike@gmail.com" },
};
}
public async Task<Patient> GetPatient(int id)
{
return await patients.FirstOrDefaultAsync(x => x.ID == id);
}
}
}