从大数据表中选择导致EF +代码超时的错误 [英] Error selecting from large data table causing time out in EF + code first
问题描述
我使用EF代码第一个模型从数据库表中获取数据,其中我有40万条记录。
但是当我使用LINQ查询时,
var urer = context.UserEntity.Where(c => c.FirstName.Contains('s'));
上面的语句给我所有的用户名字包含's'。但是,由于这是一个巨大的数据库表,它给我以下错误:
现有的连接被强制关闭远程主机
请建议我最好的方法。我将这些数据分配给gridview。我想每次获得前500名。有没有办法从EF方面做,所以我不需要在sql中做。
谢谢
1.在您的列上添加索引
2.增加超时连接
您可以创建商店流程
LINQ to SQL(第6部分 - 使用存储过程检索数据)
http:/ /weblogs.asp.net/scottgu/archive/2007/08/16/linq-to-sql-part-6-retrieving-data-using-stored-procedures.aspx
看到这个答案以及
调用具有linq服务的SQL Server存储过程
I am using EF code first model to get the data from data base table in which i have 400,000 records.
But when i use the LINQ query something like:
var urer = context.UserEntity.Where(c => c.FirstName.Contains('s'));
The above statement gives me all the user to whose first name contains 's'. But since this is a huge data base table, it is giving me the following error:
An existing connection was forcibly closed by the remote host
Please suggest me the best way to do it. I am assigning this data to gridview. I am thinking to get the first 500 each time. Is there any way to do it from EF side, so that i won't need to do it in sql.
Thanks
1.add index on your column
2. increase timeout connection
You can create Store procedure
USE LINQ call Store procedure
LINQ to SQL (Part 6 - Retrieving Data Using Stored Procedures)
http://weblogs.asp.net/scottgu/archive/2007/08/16/linq-to-sql-part-6-retrieving-data-using-stored-procedures.aspx
See this answer as well Calling a SQL Server stored procedure with linq service through c#
这篇关于从大数据表中选择导致EF +代码超时的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!