Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 运行缓慢的EF查询_Sql_Entity Framework 4 - Fatal编程技术网

Sql 运行缓慢的EF查询

Sql 运行缓慢的EF查询,sql,entity-framework-4,Sql,Entity Framework 4,我有这个查询,它运行得很慢。为什么会这样?我已经将所有非NVARCHAR(max)列添加到一个非聚集索引中,但仍然存在这个问题 return (from ir in IndemnityRatings where date >= ir.ValidFrom && date <= ir.ValidTo && ir.CoverLevel.C

我有这个查询,它运行得很慢。为什么会这样?我已经将所有非NVARCHAR(max)列添加到一个非聚集索引中,但仍然存在这个问题

return (from ir in IndemnityRatings 
                    where date >= ir.ValidFrom &&
                    date <= ir.ValidTo &&
                    ir.CoverLevel.CoverLevelId == coverLevelId &&
                    ir.Age == age &&
                    ir.OwnIndemnity == ownIndemnity &&
                    ir.CustomerIndemnity == customerIndemnity &&
                    ir.FullTimePartTimeReference == fullOrPartTime &&
                    ir.TurnoverReference == turnover
                    select ir).SingleOrDefault();
return(从ir返回,在补偿中)
其中日期>=ir.ValidFrom&&

日期什么数据库,表(RegumentRatings/CoverLevel)和索引是什么样子的?另外,两个表中的数据量是多少?表的大小是多少?索引是什么(如果有的话)表上有吗?我不认为这应该是一个索引问题,因为直接在表上运行的查询很好。赔偿表大约有29k行,coverlevel有4行。让LINQPad帮助您调试查询,查询在SQL中是OK的,而在EF中是slow的,这让我觉得EF所做的不是您认为它应该做的可能是扫描你的赔偿评级表,然后一次一个地应用where子句。你有没有在SQL事件探查器中查看这个问题是以一个还是数千个的方式影响你的数据库?