Entity Framework Powertools - Code First Generate Views On Build - entity-framework

Right now Power Tools Beta 4 provides generation of views with a right click. This is fine as far as it goes but can cause issues because you have to remember to do it.
Is there any way that I can make it do the generation of views at compile time? (i.e. some sort of pre-build action or something?
Thanks!

You can use T4 templates for generating views I created a while ago. Take a look here for the EF5 version and here for the EF6 version. You will need to do some MSBuild work to make the T4 template run on Build. You can take a look at comments for this blog post where this is discussed a little bit.
EDIT
I also recently published Interactive Views for EF6 on NuGet so now you can have pre-generated views without having to generate them at the build time.

Related

Entity Framework Pre-Generated View on Assembly

I just started using EF 6 and I noticed that the first execution takes more time because it needs to be compiled, so I researched and found that you can pre-generate the view.
I used EF Power Tool to generate the view: http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d/
It's a dll, and I'm building using the option Embed in Output Assembly.
The problem is that even though I have the view.cs when I execute the first query I have the same delay, so it seems that my library is not using the pre-generated view.
What could be wrong? I'm passing the connection to the entity using an EntityConnectionStringBuilder returning a EntityConnection object.
Also I tried changing the view.cs to Embedded Resource, since with Compile I did not have any changes, in both ways I still have the first time delay.
I'm sure I'm missing something, but not sure what.
Thanks in advance,
Lucas.
EF5 views will not work with EF6 (in addition to that there are some issues with EF6 Beta 1 and EF6 RC1 which prevent using views with EF6 - these issues should be fixed for EF6 RTM). I created a T4 template for generating views for EF6 - you can find more details here - again due to the problems above the views generated by the template will not work for EF6 RC1. If you absolutely think you need it you can try the version from my github - it was updated to work with EF6 RTM and also works with nightly builds.
Anyways, I am pretty sure that this is actually not view generation that are causing the issues (actually the performance of view generation in EF6 has been greatly improved). We recently found a few performance issues (see 1674 and 1662) that are affecting start up time and we are looking at these.
EDIT
The version of the template that works with EF6 RTM (6.0.0.0, 6.0.1.0) has been published to the VS Gallery

EntityFramework CF and Pre-Generate Views

I want to reduce startup-time by using Pre-Generate Views as described on the following link: http://msdn.microsoft.com/en-us/library/bb896240.aspx
Can I use Pre-Generate Views in Code First approach and how?
Any help would be greatly appreciated.
EF Power Tools CTP1 contain feature called Optimize Entity Data Model which should be equivalent to pre-generating views for EDMX.
Unfortunately you can not use them in Code First.
looks like Pre-generated views are not supported by Code First (no precompiled queries in EF http://blogs.msdn.com/b/adonet/archive/2011/03/02/ef-4-1-is-coming-dbcontext-api-amp-code-first-rtw.aspx ).
Here you can find some performance tips for EF : http://msdn.microsoft.com/en-us/library/cc853327.aspx
You can however reverse your DbContext and extract the EDMX using the EF Power Tools, once done that you can tune your queries.
EF Power Tools Beta 3 includes pre-generating views for Code First, as you can see at the bottom of this blog post
EF Power Tools Beta 3 Available
You can download this tool from Visual Studio Gallery

MVC 3 & ASP.Net with Entity Framework scaffolding error : No model classes are available

I am trying to use MVC3 with the Entity framework with Code First, but the code Template generation process in MS Visual Web Developer 2010 - is not detecting my Model in the models folder - giving a message - "No Model classes are available" - although I do have model classes for which I want to create controllers.
The templating option I've selected is "Controller with read/write actions and views using the Entity Framework".
I've uninstalled and reinstalled Web Developer 2010, but still having the same error.
Anyone know how I can get around this error?
xixonia's response worked for me. All I needed to do was build/rebuild the project and then everything worked as expected.
Rebuild all did not fix this issue for me... until I closed Studio, reopened and rebuilt all. Then it worked like a charm.
After create models must be build your project.
http://www.asp.net/mvc/tutorials/hands-on-labs/aspnet-mvc-4-entity-framework-scaffolding-and-migrations
I had this same issue and for me I had to go to the properties of the entity model in the entity model designer and change Code Generation Strategy to Default. It had been set to None because I had experimented with a DbContext generator.
I had this same issue.
While digging through my references, just before throwing the computer against the wall, I found that I had EntityFramework version 4.1 installed in the web project (by VS 2010 when the MVC 3 project was created).
I had 4.3.1 installed in the domain project (from nuget).
I uninstalled both of them and reinstalled from nuget.
Now everything is working again.
Hope this helps.
If you still have this problem then follow these steps to fix the problem:
1. Right click on your project and select [Manage NuGet Packages]
2. On the opened popup window, on the left hand pane, select Updates
3. On the right hand pane, at the very top right click on the Update All
During this process, it will ask you whether you want to overwrite the existing references (not sure about the exact phrase). So, say "Yes" to overwrite...
Now try to add the controller to your project and everything will be fine.
Good Luck!

Is EF4 "Code Only" ready for production use?

I've been looking at the new Entity Framework 4 Code Only features, and I really like them. But I'm having a hard time finding good resource on the feature. Everything seems to be spread around blongs here and there, so this make me wonder if it's ready to be used for a serious project?
What do you think? Is it ready for production use or should I use the more traditional approach (EDMX designer, POCO objects)?
Also, I would like to know if there are any features that Code Only does not support yet, compared to the EDMX designer?
What do you think about the Code Only feature? Is it "mature" yet?
Thank you.
It depends when your project should be ready. Code First (Code Only) is only in CTP3 without go-live license. As I've read, there is no exact timeframe for the Feature Pack Where is EntityConfiguration in EF4 VS 2010 RTM? and it will be published when it will be ready (no release date). According to the blog of EF team it will be available in the next framework release.
Code First is still under active
development and will have some
breaking changes so there is no
go-live licence at this time.
Link
Code First = Code Only
In my projects I went with EF + POCO for now.
If anyone is still looking for an answer to this, Entity Framework V4.1 which has the "Code first" feature has been RTW (released to web) for production use since a month and a half now.
You need .Net 4.0 RTM in order to install it. Once you have that installed, you can download the stand-alone installer for EF4.1 from here.

Areas over multiple projects - Views not found in child projects

I've been following this guide from MSDN about "Creating an ASP.NET MVC Areas Application Using Multiple Projects". Since ASP.NET MVC 2.0 is just preview one would imagine there to be some bugs.
My problem is, it simply doesn't work! At least not the way it's suppose to. After setting everything up and pressing F5, one would think that, this will work, neat! BEEEP. Wrong.
It doesn't find the Views in the child project! Because in my case it tries to search within ~/Views which of course is in the parent!
When debugging i see that it Does run the Controller inside my child project, but when using return View(); on that Action, it looks inside the Parent View-folders.
I ask, Bug or Feature?
Tried this in both Vs2009, Vs2010 with both Framework 3.5 and 4.0.
I put "multi project areas" in Google and came accross this post: http://forums.asp.net/p/1494640/3540105.aspx. Note specifically Phil Haack's response.
It appears that defining your views in the parent project is "functioning as designed" because of this entry in the MSDN post: Now that all the code is in place, the final step is to customize the build process for each area project. This customization causes some child-area files, such as the views, to be copied to the main project before the application is built.
The "problem" with the post is that it was defined for the beta where this build step was easily accessable. RC+ you have to point to the Futures assembly and assign the build step slightly differently if this is the path you choose.
If you don't like the direction this pushes you, the portable areas portion of MvcContrib Phil mentions is about as good as you're gonna get to an alternative.
I went through the same pain as you. This is what I did.
Made sure I was running MVC 2 RC (uninstall beta 2, install the RC).
Recreated the project from scratch.
No need to edit the csproj files, no need to create a routes.cs, and no need to edit global.ascx.cs, just right click the main project to get the context menu. From the Add menu item you can create a new area.
The views have to be in the main
project or you can use the
information in this post
http://forums.asp.net/p/1494640/3540105.aspx, which I plan on doing so the views are in each area.
It doesn't support the Multi-Project areas, but for now that's ok with me. The link above does point you in the direction for multi-project areas.