I'm getting timeouts with a very basic EF statement. I'm simply doing a select from a single table with a Entity.Title.StartsWith("test") and a .Take(25). When I run this for a search that returns no results I get a timeout.
If I profile and grab the sql statement it looks fine, and if I run that sql in Management Studio it runs in a fraction of a second!
Why would the same query run sub-second in Management Studio and timeout when generated by EF and ca开发者_如何学JAVAlled from an Asp.Net app?
It probably means you need to rebuild statistics.
This is a common symptom of an incorrectly cached query plan due to out of date statistics.
See this answer: Why are there performance differences when a SQL function is called from .Net app vs when the same call is made in Management Studio
This will update all statistics and refresh views and stored procs (but be careful about running on a Production machine):
EXEC sp_updatestats
EXEC sp_refreshview
-- Probably won't need this as your are not using stored procs
EXEC sp_msForEachTable 'EXEC sp_recompile ''?'''
精彩评论