Emre
Emre

Reputation: 31

Entity Framework Performance Problem

I am having performance problems with entity framework when the first query for the application is executed it takes around 20 seconds I checked the query's actual execution time on sql server with sql server profiler it takes some miliseconds .After the first query others work ok.

The query is an extremely simple select from a table with just one row inserted.DB consists of around 200 tables but nothing fancy in it no indexes ,views...I saw some other people also having similar problems with the first query but I could not find a solution.Any idea about what's really going on?

Well this the query

        DBEntities en = new DBEntities();

        var person= (from p in en.People
                           select p).First();
        this.txt1.Text = person.name;

Upvotes: 3

Views: 794

Answers (3)

AJ.
AJ.

Reputation: 16719

Two more options for finding where the code is killing performance: SQL Profiler and the excellent EFProf.

Upvotes: 0

Mike Bonar
Mike Bonar

Reputation: 37

If the query in the database is only taking milliseconds (less than 300), then the problem lies in the application. You need to instrument your code and log messages that tell you when events occur in the transaction. You should log before and after the call to the database so you can rule out network latency. It's likely that after the first query the results are cached so everything is fast after that. The question is whether setting up the cache or transmitting the payload is taking all the time.

Upvotes: 0

Darren Lewis
Darren Lewis

Reputation: 8488

Although the SQL query takes milliseconds, the creation of the SQL within EF maybe taking some time on first execution. Especially if it's a complex query/model. Take a look at this article that explains how you can pre-generate to improve performance. Pre-Generate Views

Upvotes: 1

Related Questions