lobirun.blogg.se

Ps ef command runs slow
Ps ef command runs slow













ps ef command runs slow

Run the same query as before (again the first query is slow and so is the SQL statement).Run the first query with EF, the SQL statement is slower then any secondary query.The slow query happens every time there is a "first query" in EF. I do not believe this to be a case of SQL Server reading from the harddisk. That is why it appears that the query is taking a lot of time on the database server because materialization time is included in the SQL Server profiler timings. Meaning that when a row is returned from the database it is immediately materialized (if it does not already exist in the context) then the next row is returned and so on. I did a test yesterday that seems to support that rows are being returned in a sequential manner. Just for testing purpose I copied the SQL that the Entity Framework generates and opened a new query window with a separate connection and executed the query in it.Īs you can see it takes 8 seconds for the first query and 4 seconds for the second. I can understand why the application doesn't use any time because there is no new rows that need to be converted to objects but why is the query so much faster, I would have expected a few seconds because of execution plans but not 24 seconds.

ps ef command runs slow

Looking at the secondary query the timings are the same for both application and SQL server but executing the query is much faster this time. The last 27 seconds is used for executing the query on SQL Server. Timings in SQL Server Profiler is for the same queries that was executed in the application which shows that the application only use about 2,6 seconds to fill data into the objects. Timings in the application was measured with the Stopwatch class. I have done some timing tests to try and find out where the problem lies and i was a bit surprised to see that it looks like it is the SQL Server that is slow on the first query. This is a big query and we may get other queries that are even bigger and it is understandable that they may be a bit slow but 30 seconds is way too slow for user to wait for especially when datasets can get the same data a lot faster. I also want to know if something can be done to increase the speed of the first query to a point where it is within acceptable limits. What I would really like to know is why the first query is soo much slower than any secondary queries.

ps ef command runs slow

I also used the T4 Views Template to pre-compile the views.

#Ps ef command runs slow generator#

The tests was done in Visual Studio 2010 using the Entity Framework 4.0 Model and the POCO generator (there isn't much difference in timings between normal entities and POCO objects). I'm loading quite a lot of rows from the database including two 0-many relationships. I have tried looking for an answer on different sites but no one seems to actually have a solution to this. As the title suggest I'm having a problem with the first query against a SQL Server database using Entity Framework.















Ps ef command runs slow