Home > database >  Create List<T> from IEnumerable<T> being returned from async function
Create List<T> from IEnumerable<T> being returned from async function

Time:07-08

How to crate a List<T> from an IEnumerable<T> after getting the IEnumerable<T> from an async function?

My code:

var orders = await _DbManager.Orders.GetAllAsync();

_DbManager.Orders.GetAllAsync() returns IEnumerable<Orders> and I want to avoid multiple-enumeration but _DbManager.Orders.GetAllAsync().ToList() gives me that error:

Task<IEnumerable> does not contain a definition for ToList....

What is the best solution to deal with this problem?

CodePudding user response:

Try

var orders = (await _DbManager.Orders.GetAllAsync()).ToList();
  • Related