问题
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