developer
developer

Reputation: 728

Entity Framework slow after upgrade from EF4 to EF6 (EntityFramework.6.2.0)

I'm upgrading an old MVC web application from EF4 to EF6 (and MVC3 to MVC5) using a guide i found on SO.

Functionally appears OK, but I've noticed performance issues.

Specific requests on the prod env for this application running MVC3/EF4 finish in under half a second. Same in my Dev system after update take seconds.

For comparison, I've created an new test MVC/EF6 solution on the same dev machine that I am working on the migrated application. I surfaced the below linq via an MCV action, and have found there is a big performance difference, between the two to applications.

Note: both the old and test application have no overheads in the controller constructor, they both only creating the dbContext, and run the query.

var sites = DB.Sites.Take(50).Include("Users").OrderBy(s => s.SiteName).ToList();

new test EF6 application: 200ms old application upgraded: 2 seconds

I have profiled the requests on SQL Server, and I can't see any problem there.

I am considering removing the ADO Entity Framework from the old project and starting by adding again. but this was a model first application, and doing this appears to remove all the partial classes, where the metadata has been defined (resulting in lots of compilation errors).

Edit

I removed the ADO Entity Framework model(edmx) and rediscovered from the database. This resulted in a lot of refactoring, due to pluralisation difference between EF4 and EF6. There were also changes to the Add/Update/Delete entities behaviours.

This hasn't resolve the performance issue.

Upvotes: 1

Views: 1495

Answers (2)

developer
developer

Reputation: 728

Solved:

in the upgraded app's web.config I found the connection string had: Pooling=False; I removed this.

Additionally in my test app, I found the connectiton string had: App=EntityFramework

The performance immediately improved to that of the test application

Upvotes: 0

gmn
gmn

Reputation: 4319

This ones going to be really hard to debug from afar but I'd start by capturing the query thats being created by ef with sql profiler and seeing if you're missing any indexes on the db. SQLServer is a temperamental beast when it comes to producing query plans and if EF has changed its queries from 4 to 6, and theres a reasonable amount of data in the tables, this is most likely to be causing your issue. You might find it just needs a new index or something along those lines.

Another option thats not specifically tied to your problem, but could have an effect is precompiling the views in the EF context, which should reduce the first query time after startup of the application.

Upvotes: 1

Related Questions