Entity Framework Code-First too slow at startup

我只是一个虾纸丫 提交于 2020-01-04 10:14:12

问题


I know this has been asked a lot before, but I still haven't found a working fix.

I'm creating a desktop application which will regularly be started and stopped. The database is a MySQL database stored online and I'm using the newest version of EF and the MySQL connector.

I'm also working code-first. For now, I only have 3 small entities, but these will grow a lot in time. The database is generated already at startup, so nothing needs to be created anymore.

Every time the application is started (even when deployed), retreiving the first data from the database (only like 50 records, but I've also tried only 10 and it doesn't make any difference) is slow: around 5 seconds. After that, the next queries are pretty fast (around 1 second).

I've already tried generating views, but it doesn't change anything. I also create only 1 DbContext.

If I attempt to use ADO.NET, I get the results almost instantly, even on the first query (retreiving all 50 records), so it has nothing to do with a connection issue.

I'm not sure what information I have to give in order for you to help me, so feel free to ask more info.

Any idea what I could try? Is it really supposed to take like 5 seconds before the user can start working with the program?


回答1:


On EF the first a query is run it has to be compiled even though the program is already complied.

I would suggest reading this http://www.codeproject.com/Articles/38174/How-to-improve-your-LINQ-query-performance-by-X and this https://msdn.microsoft.com/en-us/library/vstudio/bb896297%28v=vs.100%29.aspx and trying again to see if this helps.

Good luck!



来源:https://stackoverflow.com/questions/28338613/entity-framework-code-first-too-slow-at-startup

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