3

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?

NickH
  • 351
  • 5
  • 15
  • 2
    According to [this article](http://blogs.msdn.com/b/adonet/archive/2012/03/22/ef5-beta-2-available-on-nuget.aspx) Power Tools CTP 2 should be available soon and I guess the new version will support EF 4.3 and EF 5. – Ladislav Mrnka Mar 27 '12 at 12:07
  • So after a few more hours of time wasting, it seems that MySql was part of the problem and this post fixed that. http://www.devart.com/blogs/dotconnect/index.php/using-entity-framework-power-tools-ctp1-with-oracle-mysql-postgresql-and-sqlite.html The remaining thing I need to figure out is how to generate the Context.View.cs file as part of our build process. I'll ask on the EF Power Tools Q&A and report back in case it helps someone else out. – NickH Mar 27 '12 at 12:54
  • http://blogs.msdn.com/b/adonet/archive/2012/03/22/ef5-beta-2-available-on-nuget.aspx : "EF Power Tools Beta 2 is Coming Entity Framework has progressed a lot in the last 6 months and we’ve let the Power Tools fall behind. We are working on an updated version at the moment and we’re aiming to have it available in the next couple of weeks." – Pawel Mar 27 '12 at 20:31

2 Answers2

1

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.

Community
  • 1
  • 1
Scott Stafford
  • 43,764
  • 28
  • 129
  • 177
0

I have encountered this same error when I am running VS2010, EF v4.3.1 and Entity Framework Power Tools Beta 2. The solution for me was to run Visual Studio as admin. (Done by right clicking the Icon and select "run as administrator" from the context menu.) At that point I was able to use the "generate views" option in EFPT.

Adam Lenda
  • 700
  • 6
  • 13