Trouble with Entity Framework Linq Query: runs instantly in SSMS and 8-10s in EF LINQ Trouble with Entity Framework Linq Query: runs instantly in SSMS and 8-10s in EF LINQ sql sql

Trouble with Entity Framework Linq Query: runs instantly in SSMS and 8-10s in EF LINQ


You could try using IQueryable.AsNoTracking() see http://msdn.microsoft.com/en-us/library/gg679352(v=vs.103).aspx. It is safe to use AsNoTracking() in cases where you are not going to edit the results and save them back to the database again. Usually it makes a big difference when a Query returns a large number of rows. Make sure you put System.Data.Entity in your uses if you want to use .AsNoTracking()


It could be a problem of cached execution plan. Try execute stored procedure to clean query execution plans:

DBCC FREEPROCCACHE

Also this thread might be helpful: Entity Framework cached query plan performance degrades with different parameters