为EF代码首先生成视图 [英] Pre-Generate Views for EF Code First

查看:170
本文介绍了为EF代码首先生成视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

终于部署了一个使用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电动工具CTP1看起来很有前途,除了EF 4.3似乎被破坏,还没有更新几个月。另外我不知道该工具如何适应我们的自动构建过程。



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

  System.Reflection.TargetInvocationException:
异常被调用的目标抛出。 ---> System.Data.ProviderIncompatibleException:提供程序未返回ProviderManifestToken字符串。 ---> System.Data.SqlClient.SqlException:
与SQL Server建立连接时发生与网络相关或实例特定的错误。服务器未找到或无法访问。验证实例名称是否正确,并将SQL Server配置为允许远程连接。 (提供者:SQL网络接口,错误:26 - 定位服务器/实例指定错误)

这可能是MySql相关的,但EF Power Tools Q& A部分的其他几个报告。



那么简而言之,如何预先生成EF的视图4.3代码优先,可以插入自动构建过程的方式?

解决方案

Pawel回答了我的相关问题: p>

通过构建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个表,使用起来变得越来越烦人。


Having finally deployed to live a new site built with Entity Framework Code First and MySql, one nagging annoyance is the pause often experienced while view metadata is cached. This seems to happen far more frequently than the application pool is recycled. (?)

I guess that for a site which has a constant stream of traffic this might not be noticed often. For a new site with infrequent traffic it feels like every time I go to the site there's a 4-5 second delay in rendering the first page.

So I tracked down the following links:

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

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

The EF Power Tools CTP1 looked promising, apart from the fact that it seems to be broken for EF 4.3 and hasn't been updated for months. Also I'm not sure how that tool would fit in to our automated build process.

The OptimizeContext() or WriteEdmx() methods that EF Power Tools is using throw this error

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)

I initially assumed this might be MySql related but several others on the EF Power Tools Q&A section are reporting it.

So, in short, how do I pre-generate views for EF 4.3 code first, preferable in a way that can slot into an automated build process?

解决方案

Pawel answered my related question:

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

by building T4 templates:

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

which also aren't perfect, but more usable than anything else that I've seen.

You could then do something like:

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

to add it to the build process, but it's sort of slow and so you might want to just leave it as a(nother) manual step in updating the EF model.

Really, they need a warning that says, DON'T USE EF WITH > 500 TABLES, it becomes increasingly annoying to use.

这篇关于为EF代码首先生成视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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