Entity Framework Async: Unexpected Performance Bottleneck
Migrating to asynchronous controllers and database operations (using ToListAsync()
instead of ToList()
) often improves application performance. However, this isn't always the case. In a recent scenario, switching to asynchronous methods dramatically slowed down query execution. The following query, retrieving "Album" objects with a simple database join, exemplifies this issue:
<code class="language-csharp">var albums = await this.context.Albums .Where(x => x.Artist.ID == artist.ID) .ToListAsync();</code>
The generated SQL query is (truncated for brevity):
<code class="language-sql">SELECT [Extent1].[ID] AS [ID], [Extent1].[URL] AS [URL], [Extent1].[ASIN] AS [ASIN], ...</code>
The above is the detailed content of Why Are My Entity Framework Async Operations Slower Than Synchronous Ones?. For more information, please follow other related articles on the PHP Chinese website!