Entity Framework takes about 30 seconds on first request

I am using Entity Framework 6 in a SQL Server database to query an existing database (first a database, so there is EDMX in my project).

I noticed that the first time I request an object, it can take up to thirty seconds to complete the request. Then subsequent requests to the same object are completed in milliseconds. Actually, the SQL that is executed is very fast, so this is not a slow query.

I found that the Entity Framework generates background views and that this is the most likely culprit. However, I did not find a good solution for this. There is a NuGet package that can handle Generation view (EFInteractiveViews), but it has not been updated since 2014, and I hardly find information on how to use it.

What options do I currently have? I tried to initialize the Entity Framework to Application_Start by executing a few requests, but this does not seem to help at all, and it is also quite difficult to execute real requests on Application_Start, because most requests use data from the current user (who has not logged in yet Application_Start), so it's hard to run them in advance.

I was thinking of creating an ashx file that constantly checks the application by calling the API and saving it. I also set the application pool to AlwaysRunning so that EF does not restart when reusing the application pool.

Does anyone have any tips or ideas on how I can solve this or something that I can try?

Many thanks. I spent most of two days looking for a viable solution.

+4
source share
2 answers

There are many ways to speed up the Entity Framework, I mentioned some of them

  • LazyLoading (EDMX = > = > properties = > Lazy Loading Enabled false)

  • AsNoTracking().ToList(), , Attach EntityState.Modified

  • Indexes

  • Paging,

  • Edmx , , ( )

  • " ", Include, using System.Data.Entity, lambda include

Edmx

: Country, City, Person, Car, Rent, Gender, Engine, Manufacturers,.. .

  • , (CRUD), , Car, Rent, Manufacturer, ManagePerson.edmx (Country, City, Person, Gender)

  • (CRUD) Car, (Person, City, Gender, Rent), ManageCar.edmx, (Car, Manufacturer, Country, Engine)

+3

Entity Framework LINQ SQL, . , , , .

EF, , , ( ), .

. Hadi Hassans .

+1

Source: https://habr.com/ru/post/1655322/


All Articles