Entity Framework Startup optimization

Source: Internet
Author: User

EF+MVC's website will be slow when it first opens, and it will be slow to restart the application pool if it is idle for a while.

program updates, the application pool restarts, and after recycling, the program files need to be reloaded.

1, install application initialization

This is IIS8 's built-in feature, and for IIS7.5, Microsoft provides an extension package to support this feature.

Application initialization Module for IIS 7.5

Http://www.iis.net/downloads/microsoft/application-initialization

This extension does not provide the interface, need to operate the interface, you need to download the third-party plugin Applicationinitializationinstaller

Configure the application pool for StartMode to alwaysrunning

Configure the site to open preload and Doappinitafterrestart

2. NGen to generate the local image of EF

EF is no longer defaulted from version 6 with the. Net framework installation, and when the program starts, EF compiles the MSIL by Just-in-time compiler to the cost code, which is stored in memory.

Use the cmd command prompt to enter the directory where the project DLL is located, typically bin, running NGen

32bit

%windir%\microsoft.net\framework\v4.0.30319\ngen Install EntityFramework.SqlServer.dll

64bit

%windir%\microsoft.net\framework64\v4.0.30319\ngen Install EntityFramework.SqlServer.dll

3. Disable _migrationhistory

When Code first accesses EF, it accesses _migrationhistory and checks to see if the database matches the entity class to ensure that EF works correctly.

Application_Start the code Database. Setinitializer<myContext> (null) to disable this feature.

Entity Framework Startup optimization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.