4
votes

Struggling to create Entity Framework precompiled views for database and need help.

While using Visual Studio 2010, I have been unable to generate precompiled views using latest version of the Entity Framework Power Tools Beta 3. When I right mouse click on the dbContext based file and select "Generate Views" option, it pops up a "Sequence contains no matching element" dialog error box.

Uninstalling the power tools extension, rebooting Visual Studio and computer has not helped.

Question 1: What could be causing this error. Entity Framework Power Tools is worthless until I can get it working?

So up until now the only way I'm able to generate views for this sequence is by using a T4 template (from Internet) but it often times-out and fails to complete. The database has about 350 tables and the number of views it creates is about 670 views. However, it fails to create the views the majority of the time and I have to repeatedly try and sometimes shut down and reboot to get it to work. CPU utilization during this time is about 12% on an i7 Quad core with SSD and 8GB of memory so it's strange. However when the views are generated (no timeout) they work fine.

Question 2: Is there anything that can be done to keep this template from timing-out and failing?

Now unable to just give up I've looked into trying other ways, I was able to generate the views by creating a database first project and adding an Entity Framework Data Model created from an existing database. The model is created fine and I'm able to create the views as expected but they are not recognized when placed in the final assembly and entity tries to query the database. When placing in the assembly I replaced the view file that works when generated using T4 template the file created by the Power Tools context menu.

Is the namespace causing this problem?

I think it has something to do with the namespace but I don't know the rules on how it finds out the compiled views and what does the namespace and views have to be called in order to be found and used. The views created from the DbContext file is in a different project than the views created using the Edmx model of the same database. I have a DbContext project a Model Project a Domain Classes project and Domain Class Mapping project. I place the views file in the same assembly (project) as the Domain Classes.

Here is an example of the generated view output. The one on the left was created using a T4 template and "Run Custom Tool" and the one on the right was created with Entity Framework Power Tools Beta 3 and selecting "Create Views" from context menu while cursor on the EDMX file.

Working one:

SELECT VALUE [xxx.yyy.Provider.DataContext.RouteStop](T1.RouteStop_RouteStopId, ...
FROM (
     SELECT   T1.RouteStopId as RouteStop_RouteStopId, .....
     FROM     CodeFirstDatabase.RouteStop AS T
     ) AS T1

Not working one:

SELECT Value [xxx.yyy.Provider.DataModel.Store.RouteStop](T1.RouteStop_RouteStopId, ...
FROM (
     SELECT   T1.RouteStopId as RouteStop_RouteStopId, .....
     FROM     ZeeZorProviderEdmx.RouteStops AS T
     ) AS T1

The namespace for the project that contains the Domain classes and also contains a copy of the generated views is "xxx.yyy.Provider.DomainClasses" if that helps.

Question 3: How do I get the Power Tools generated views from EDMX working like the other view files create from T4 Template.

I've been losing hear over this and I don't have much left anyway so I could really use some good advice. I need a solution and I see one of 3 ways:

  1. Use Entity Framework Power Tools Beta 3 and the "Create Views" context menu option when DbContext based object file is selected.

  2. Use the T4 template and just grin and bear the timeout issues and constant failures when building the views.

  3. Use the Model project with EDMX file and use the Power Tools Beta 3 "Create Views" context menu and solve the namespace or view discovery issue.

Please help me figure out one of these 3 ways and get it working.

Thanks, Blake

3
Got another possible solution after having similar problem while working on another project. When connecting to Oracle using the ODP.NET managed driver, I did not have a reference to that Oracle DLL (Oracle.ManagedDataAccess.dll) in my project containing the context and "Create pre-compiled Views" kept saying "Sequence contains no elements". I added the reference and the problem went away and views could be compiled. So it appears, that not only do you have to makes sure you connection string is right but also that you have a reference to the proper 'providerName' in the app.config. - Blake

3 Answers

2
votes

OK - I've just had this issue when trying to view the View Entity Model from the power tools menu. Sequence contains no elements. Looks like things are still under construction with the Tools Beta 3. The cause is apparently that the power tools cant find the connection string. Anyway, here is a temporary solutions that works.

Add a new Class Library project to your solution. You can remove the default class1 if you want. Now, add a App.config file with a connection string element. (I just copied mine from the real App.config. Then, set this project as the Startup project. Now, when you click on the View Entity Model as readonly menu item, it will display.

I guess the guys are working on this issue. Julie Lerman blogged about it in the link mentioned above.

Hope this solves some of your issues.

1
votes
0
votes

Had the same problem, but different cause. Context: EF was used with Oracle database

One of the columns was mapped to CLOB column type, which EF Power Tolls didn't like, although when working with database EF was able to use it no problem.

Property(l => l.MyField).HasColumnName("MY_FIELD").HasColumnType("CLOB");