Startup/first query extremely slow

吃可爱长大的小学妹 提交于 2020-01-01 03:49:24

问题


It takes a while (3 minutes+) to 'create/compile' my DbContext. The web server starts in about 5 seconds, but when I do the first query to my database, EF 2.0 has to 'build/create/compile' the database in memory or something, I think? The next requests are almost instant. This was a Database First creation of the DbContext, the database already exists in MSSQL and has data. The DbContext contains about 500 DbSet's with relations.

Is there a way to speed this up by doing the 'creation(mapping?)' of my Entity Framework's DbContext before running the web server (at developmenttime), create the file/mappings it needs, so the first request is fast too?


回答1:


In general this is normal Entity framework behavior by default, but from other side of cause there are some ways to resolve this course of things.

For example you can try:

  • disable database initialization
  • using pre-generation views
  • "warm" loading

Please try to read this articles:

  • https://msdn.microsoft.com/en-us/library/hh949853(v=vs.113).aspx
  • https://www.fusonic.net/en/blog/3-steps-for-fast-entityframework-6.1-code-first-startup-performance/
  • https://www.fusonic.net/en/blog/ef-cache-deployment/


来源:https://stackoverflow.com/questions/46683370/startup-first-query-extremely-slow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!