1

I have a problem with a quite complex query executed through Entity Framework that takes so much time, almost 50 seconds. The query is executed with an ad-hoc call to a web service which creates a new ObjectContext, execute the query and returns the result.

The problem is that if I trace with SQL Server Profiler the T-SQL code and try to execute it from SQL Server Management Studio it takes like 2 seconds... what could it be?

Thank you, Marco

1 Answer 1

2

For every ObjectContext that touches the database, Entity does a lot of startup work building an internal representation of the database schema. This can take a long time (our project is about 30 seconds), and is rolled into the expense of the first query made against the database. Subsequent ones are plenty fast, until the process is restarted. Does that apply to you?

Sign up to request clarification or add additional context in comments.

3 Comments

but if I declare a new objectcontext entity framework recreate the database schema? because i don't restart the application
"new ObjectContext" won't cause the metadata to be re-created. However, if IIS is killing the process or something every time... You need to post some code so we can see whats going on. Need to see how you're executing the query on both the client and server.
Sorry I can't post code because it is protected and I am not allowed to, but basically the client call the service that create a new class in the DAL layer which instances the object context and makes the query. The objectcontext will be disposed but IIS doesn't kill the process...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.