简体   繁体   English

使用具有较大结果集的实体框架5的性能问题

[英]Performance problems using entity framework 5 with large resultset

I'm using Entity Framework 5, and I'm executing a query that returns a relatively large resultset, around 30,000 rows. 我正在使用Entity Framework 5,并且正在执行一个查询,该查询返回相对较大的结果集(约30,000行)。 The query itself executes very fast, taking only around 700ms. 查询本身执行速度非常快,仅需700毫秒左右。

After building the linq query I call query.Load(); 构建linq查询后,我调用query.Load(); , and then return DataContext.Set<MyType>.Local as an ObservableCollection to the caller. ,然后将DataContext.Set<MyType>.Local作为ObservableCollection返回给调用方。 The results are displayed in an editable grid. 结果显示在可编辑的网格中。

The problem is with the query.Load(); 问题出在query.Load(); call - it's taking around 60 seconds, which is way too long. 通话-大约需要60秒,这太长了。 I'm guessing that this is where EF transforms the results into .NET objects? 这是EF将结果转换成.NET对象的地方吗? I've tried profiling, but it won't go any deeper than IQueryable.Load :/ 我已经尝试进行概要分析,但是它不会比IQueryable.Load更深入:

Any ideas how can I improve performance? 有什么想法可以改善绩效吗?

BTW, I tried upgrading to EF6 to see if that helped any, but it actually got worse, wih query.Load(); 顺便说一句,我尝试升级到EF6看看是否有帮助,但实际上变得更糟了, query.Load(); typically taking 100 seconds! 通常需要100秒!

The Linq to Entities query is not executed until the results are needed. 在需要结果之前,不执行Linq to Entities查询。 That's when the computational cost is "paid". 那时计算成本是“支付”的。 Until then, the query is just a query. 在此之前,查询只是一个查询。 As Stefan suggested, you should try add some filters, or at least a paging mechanism using .Skip and .Take methods. 正如Stefan所建议的那样,您应该尝试添加一些过滤器,或者至少使用.Skip和.Take方法添加分页机制。

You could also check this MSDN article about linq paging. 你也可以查看有关LINQ分页MSDN文章。

Hope I helped! 希望我能帮上忙!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM