W
W
WannaBePro2021-07-26 18:03:33
C++ / C#
WannaBePro, 2021-07-26 18:03:33

AsEnumerable vs ToArrayAsync?

Foreword: I want to understand, the articles do not write clearly.

There is a handler ( scoped handler)
Is there a difference (advantage) what to use when building / executing queries, AsEnumerable or ToArrayAsync ?
After the request, additional filtering and grouping is performed, but already on the server.
On the one hand, ToArrayAsync executes the request asynchronously and does not block the thread, but AsEnumerable does not seem to be executed immediately either (whether there will be blocking when used) ...

And will there be a significant increase in medium / high load, or these approaches do not have a strong difference in standard cases ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2021-07-26
@WannaBePro

ToArrayAsync executes the request asynchronously and does not block the thread

It's right.
AsEnumerable seems to be also not executed immediately (whether there will be locks when used)

You will get back an IEnumerable. The request will be executed when the first member of the thread-blocking enumeration is received. For a multi-threaded server application, use ToArrayAsync, ToListAsync, ToDictionaryAsync.
AsEnumerable is not commonly used.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question