LINQ to SQL在大型数据库中的效率问题 [英] LINQ to SQL efficiency issues in large data bases

查看:75
本文介绍了LINQ to SQL在大型数据库中的效率问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在对linq执行查询SQL 对象。
这是债券到一个大型数据库(超过一百万条记录)。 我想过滤所以查询不需要
10分钟才能运行。 当我尝试使用以下方法过滤
时,它非常非常慢。 如何查询 使用LINQ可以有效地使用
进行前100行。

I am executing a query on a linq to SQL  object.  It is bond to a large database (over a million records).  I want to filter so the query does not take 10 minutes to run.  When I try and filter using the following method it is very, very slow.  How can I query   geting the top 100 rows as efficiently as possible using LINQ. 

代码是:

return from s in dataContext.PatientTable select
s).Take(100).ToList( );

  return (from s in dataContext.PatientTable select s).Take(100).ToList();

谢谢,

k

推荐答案

上面的示例查询应该转换为"从耐心表中选择前100名[表格中的所有字段]"。

如果这很慢,那么有趣的事情正在发生 - 也许你被别人的锁阻挡了?或者,除了上面的示例之外,您的真实查询还有更多内容吗? (例如,orderby,where子句,加载选项,......?)

使用SQL分析器查看发生了什么,尝试进行脏读,当然还要在mgmt studio / query analyzer中测试相同的查询。

和/或发布更多细节;表模式,dbml或类定义,dc初始化等。
Your sample query above should translate to "select top 100 [all fields in the table] from patienttable".

If that is slow then something funny is going on - maybe you're being blocked by someone else's locks? Or is there more to your real-life query than the example above? (e.g. orderby, where clause, load options, ...?)

Use SQL profiler to see what is going on, try doing dirty reads, and of course test the same queries in mgmt studio / query analyzer.

And/or post more details; table schema, dbml or class definition, dc initialization etc.


这篇关于LINQ to SQL在大型数据库中的效率问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆