2
实体框架异步操作需要十倍的时间才能完成
我有一个使用Entity Framework 6处理数据库的MVC站点,并且我一直在尝试对其进行更改,以使所有内容都作为异步控制器运行,并且对数据库的调用作为它们的异步对应对象(例如ToListAsync()而不是ToList()) 我遇到的问题是,仅将查询更改为异步已使它们的运行速度变得异常慢。 以下代码从我的数据上下文中获取“相册”对象的集合,并转换为相当简单的数据库联接: // Get the albums var albums = await this.context.Albums .Where(x => x.Artist.ID == artist.ID) .ToListAsync(); 这是创建的SQL: exec sp_executesql N'SELECT [Extent1].[ID] AS [ID], [Extent1].[URL] AS [URL], [Extent1].[ASIN] AS [ASIN], [Extent1].[Title] AS [Title], [Extent1].[ReleaseDate] AS [ReleaseDate], [Extent1].[AccurateDay] AS [AccurateDay], [Extent1].[AccurateMonth] AS [AccurateMonth], [Extent1].[Type] AS [Type], [Extent1].[Tracks] AS …