【问题标题】:Pre-Generate Views for EF Code FirstEF Code First 的预生成视图
【发布时间】:2012-03-27 11:34:07
【问题描述】:

最终部署到使用 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 代码预生成视图,最好以一种可以插入自动构建过程的方式?

【问题讨论】:

  • 根据this article Power Tools CTP 2 应该很快就会推出,我猜新版本将支持 EF 4.3 和 EF 5。
  • 所以在浪费了几个小时之后,MySql 似乎是问题的一部分,这篇文章解决了这个问题。 devart.com/blogs/dotconnect/index.php/… 我需要弄清楚的剩下的事情是如何生成 Context.View.cs 文件作为我们构建过程的一部分。我会在 EF Power Tools Q&A 上提问并报告,以防它帮助其他人。
  • blogs.msdn.com/b/adonet/archive/2012/03/22/… : "EF Power Tools Beta 2 即将推出 实体框架在过去 6 个月中取得了很大进步,我们让 Power Tools 落后了。我们正在开发更新版本此刻,我们的目标是在接下来的几周内提供它。”

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


【解决方案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 模型的(另一个)手动步骤。

真的,他们需要一个警告,上面写着,不要在超过 500 个表的情况下使用 EF,使用它会变得越来越烦人。

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-17
      • 2014-04-22
      • 2011-09-11
      • 1970-01-01
      • 1970-01-01
      • 2012-01-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多