3

最终部署到使用实体框架Code First和MySql构建的新网站后,一个恼人的烦恼就是缓存视图元数据时经常遇到的暂停。这似乎比应用程序池被回收的频率要高得多。 (?)EF代码优先的预生成视图

我想对于一个拥有恒定流量的网站来说,这可能不会经常被注意到。对于流量不频繁的新网站,感觉像每次访问该网站时,第一页的渲染都会延迟4-5秒。

所以我就找到了下面的链接:

http://msdn.microsoft.com/en-us/library/bb896240.aspx

http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d

的EF电动工具CTP1看起来前途无量,除了因为它似乎是EF 4.3和不是招被打破”已经更新了几个月。此外,我不确定该工具如何适应我们的自动构建过程。该EF电动工具的使用抛出这个错误

System.Reflection.TargetInvocationException: 
Exception has been thrown by the target of an invocation. ---> System.Data.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string. ---> System.Data.SqlClient.SqlException: 
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) 

我最初以为这可能是mysql有关,但

的OptimizeContext()或WriteEdmx()方法中的一些人对EF电动工具Q &一节报告。

因此,简而言之,我如何为EF 4.3代码首先预生成视图,最好能插入自动生成过程中?

+2

根据[本文](http://blogs.msdn.com/b/adonet/archive/2012/03/22/ef5-beta-2-available-on-nuget.aspx)电动工具CTP 2应该很快就可以使用,我想新版本将支持EF 4.3和EF 5. – 2012-03-27 12:07:37

+0

因此,在浪费了几个小时的时间之后,MySql似乎成了问题的一部分,这篇文章解决了这个问题。 http://www.devart.com/blogs/dotconnect/index。php/using-entity-framework-power-tools-ctp1-with-oracle-mysql-postgresql-and-sqlite.html 我需要弄清楚剩下的事情是如何生成Context.View.cs文件作为部分我们的构建过程。 我会询问EF Power Tools问题解答并报告,以便帮助其他人解决问题。 – NickH 2012-03-27 12:54:04

+0

http://blogs.msdn.com/b/adonet/archive/2012/03/22/ef5-beta-2-available-on-nuget.aspx:“EF Power Tools Beta 2即将推出 实体框架有在过去的6个月中取得了很大进展,我们已经让Power Tools落后了,目前我们正在开发一个更新版本,我们的目标是在接下来的几周内推出。“ – Pawel 2012-03-27 20:31:13

回答

1

帕维尔回答我相关的问题:

Entity Framework initialization is SLOW -- what can I do to bootstrap it faster?

通过建立T4模板:

http://blog.3d-logic.com/2012/05/28/entity-framework-code-first-and-pre-generated-views/

这也并不完美,但比其他任何东西,我有更多的可用看到。

然后,你可以这样做:

http://www.platinumbay.com/blogs/dotneticated/archive/2009/08/28/running-t4-templates-with-msbuild.aspx

将其添加到构建过程,但是这有点慢,所以你可能只想把它作为(另)一个手动工序更新EF模型。

真的,他们需要警告说,不要使用EF 500以上的表格,它会变得越来越讨厌使用。

0

我在运行VS2010,EF v4.3.1和Entity Framework Power Tools Beta 2时遇到了同样的错误。对于我来说,解决方案是以管理员身份运行Visual Studio。 (通过右键单击图标并从上下文菜单中选择“以管理员身份运行”完成)。此时,我可以使用EFPT中的“生成视图”选项。