Profiling shows slow performance when explicitly loading related entities

烈酒焚心 提交于 2019-12-13 02:06:18

问题


I have tried to profile my wpf application concentrating on non-visual parts that do some calculations and evaluations, I have used Visual Studio 2012 bulit in profiler.

There is quite a lot of code (tens of thousands of lines) in that application, so I was surprised that it showed 46.3% time spent on a single line:

db.Entry(qzv.ZkouskaVzorku).Collection(p => p.VyhodnoceniZkouskies).Load();

This line should just explicitly load related entities as specified here.

I have checked this line using SQL Express profiler and it showed only this SQL command:

exec sp_executesql N'SELECT 
    [Extent1].[VyhodnoceniZkouskyID] AS [VyhodnoceniZkouskyID], 
    [Extent1].[Kontext] AS [Kontext], 
    [Extent1].[NormaVlastnostiID] AS [NormaVlastnostiID], 
    [Extent1].[ZkouskaVzorkuID] AS [ZkouskaVzorkuID], 
    [Extent1].[ZkouskaTypuID] AS [ZkouskaTypuID], 
    [Extent1].[JeShodaITT] AS [JeShodaITT], 
    [Extent1].[JeITT] AS [JeITT], 
    [Extent1].[JeStorno] AS [JeStorno]
    FROM [dbo].[VyhodnoceniZkousky] AS [Extent1]
    WHERE [Extent1].[ZkouskaVzorkuID] = @EntityKeyValue1',N'@EntityKeyValue1 int',@EntityKeyValue1=1816601
go

And this command executes very quickly in 0 ms as it is just selecting several rows using primary clustered index.

Using Entity framework 6.1.0 with SQL Server LocalDB 2014. I have commented this line as it is important only for ViewModels and the calculations really work cca 2x faster.

What could be the issue and is there any workaround to fix it?

来源:https://stackoverflow.com/questions/32628878/profiling-shows-slow-performance-when-explicitly-loading-related-entities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!