I'm trying to convert data access synchronous query to asynchronous, so far I converted everything except selecting list which returns IQueryable<T>.
Here's what I have done so far:
[Dependency]
public SampleContext db { get; set; }
public async System.Threading.Tasks.Task<Profile> Add(Profile item)
{
db.Profiles.Add(item);
await db.SaveChangesAsync();
return item;
}
public async System.Threading.Tasks.Task<Profile> Get(string id)
{
return await db.Profiles.AsNoTracking().Where(i => i.Id == id).FirstOrDefaultAsync();
}
public async System.Threading.Tasks.Task Remove(string id)
{
Profile item = db.Profiles.Find(id);
item.IsDeleted = 1;
db.Entry(item).State = EntityState.Modified;
await db.SaveChangesAsync();
}
public async System.Threading.Tasks.Task<bool> Update(Profile item)
{
db.Set<Profile>().AddOrUpdate(item);
await db.SaveChangesAsync();
return true;
}
Above code works well, I'm stuck at converting this piece of code:
public IQueryable<Profile> GetAll()
{
return db.Profiles.AsNoTracking().Where(i => i.IsDeleted == 0);
}
How do I convert above code to asynchronous? I tried this sample code by Stephen Cleary but can't figure out what is ProcessEventAsync and how do I apply this to my code. Also, I can't use .ToList(), this will be too expensive to load all the data in memory.