为EF代码预先生成视图

时间:2012-03-27 11:34:08

标签: entity-framework entity-framework-4 entity-framework-4.3

最终部署到使用Entity Framework Code First和MySql构建的新站点,一个令人烦恼的烦恼是在缓存视图元数据时经常遇到的暂停。这似乎比应用程序池回收的频率高得多。 (?)

我想对于一个拥有恒定流量的网站,这可能不会经常被注意到。对于一个交通频繁的新网站,我觉得每次去网站时,第一页都会有4-5秒的延迟。

所以我追查了以下链接:

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

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

EF Power Tools CTP1看起来很有前途,除了它似乎已经被EF 4.3打破并且几个月没有更新。此外,我不确定该工具如何适合我们的自动构建过程。

EF Power Tools正在使用的OptimizeContext()或WriteEdmx()方法抛出此错误

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相关,但EF Power Tools Q& A部分的其他几个人正在报告它。

因此,简而言之,我如何首先为EF 4.3代码预先生成视图,最好是以可以插入自动构建过程的方式?

2 个答案:

答案 0 :(得分:1)

Pawel回答了我的相关问题:

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 WITH> 500 TABLES,使用起来越来越烦人。

答案 1 :(得分:0)

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