[英]EF calls and returns from stored procedure fast but then converting it to list takes 20 seconds for 1000 records
I am debugging a piece of code which is using EF as ORM. 我正在调试使用EF作为ORM的一段代码。 Now, I am seeing somewhat interesting behavior from the application: 现在,我从应用程序中看到了一些有趣的行为:
This is the code where I'm calling a stored procedure: 这是我调用存储过程的代码:
List<RequestListEntity> results = new List<RequestListEntity>();
var temp = System.Data.Object.ObjectContext.ExecuteFunction<T>("storedProcedure", param);
foreach (var item in temp)
{
results.Add(item);
}
Observations: 观察结果:
objectResult<T>
with a total of 1000 entries. 当我使用上面显示的代码从C#调用存储过程时,它还会在一秒钟内返回并返回带有总共1000个条目的objectResult<T>
。 Now this raises a lot of questions: 现在,这引发了很多问题:
The performance issue is because of lazy loading and object tracking. 性能问题是由于延迟加载和对象跟踪。 when this method called result maps to an entity type, two things happen that don't happen when context.Database.SqlQuery is executed : 当此名为result的方法映射到实体类型时,执行context.Database.SqlQuery时不会发生两件事:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.