实体框架代码 - 启动时首先太慢 [英] Entity Framework Code-First too slow at startup

查看:92
本文介绍了实体框架代码 - 启动时首先太慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这已经被问了很多,但是我还没有找到一个工作修复。



我正在创建一个桌面应用程序,它将定期开始停止数据库是在线存储的MySQL数据库,我使用的是最新版本的EF和MySQL连接器。



我也是首先编写代码。现在,我只有3个小实体,但是这些实体会在很长的时间里增长。数据库已在启动时生成,因此无需再创建。



每次应用程序启动(即使部署时),都会从数据库中检索第一个数据(只有50条记录,但是我也只尝试了10次,没有任何区别)慢:5秒左右。之后,下一个查询很快(约1秒钟)。



我已经尝试生成视图,但是并没有改变任何内容。我也只创建一个DbContext。



如果我尝试使用ADO.NET,我几乎立即得到结果,即使是第一个查询(查看所有50条记录)所以与连接问题无关。



我不知道为了帮助我,我必须提供什么信息,所以随便问更多的信息。



任何想法我可以尝试什么?在用户开始使用程序之前,是否真的需要5秒钟?

解决方案

在EF上首次查询即使该程序已经被编译,运行它也必须被编译。



我建议阅读这个 http://www.codeproject.com/Articles/38174/How-to-improve-your- LINQ-query-performance-by-X 和这个 https://msdn.microsoft.com/en-us/library/vstudio/bb896297%28v=vs.100%29.aspx ,然后再次尝试看看是否有帮助。 p>

祝你好运!


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?

解决方案

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!

这篇关于实体框架代码 - 启动时首先太慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆