MTS
MTS

Reputation: 114

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

How to create 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?

Upvotes: 2

Views: 650

Answers (1)

LYass
LYass

Reputation: 624

Try

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

Upvotes: 6

Related Questions