EF6 CodeFirst View Generation T4 Template for C# updated for EF6 RTM

The story around pre-generated views in pre-release versions of EF6 was far from glorious. First, things did not work in EF6 Beta1 due to this bug. Then the bug was fixed but due to other changes in this area pre-generated views were broken again in EF6 RC1 (mainly because of the combination of this and this). Because of the issues in the EF6 RC1 I decided not to post the version I had – it just did not work. Finally, it turned out that due to changes in the EF Tooling shipping with Visual Studio 2013 the template did not want to work on Visual Studio 2013 (or Visual Studio 2012 where the new tooling is available out-of-band). That’s a pretty interesting story on its own but for me it meant that I basically had to rewrite the template. Today EF6 has finally landed (btw. Visual Studio 2013 shipped today too) Since the bugs around pre-generated views were fixed I updated the EF6 Code First T4 template for generating views and posted the latest version on the Visual Studio Gallery. The template should work on Visual Studio 2010, Visual Studio 2012 and Visual Studio 2013 and for EF6 RTM and nightly builds. If you need steps to install and use the template take a look at this post.
A couple additional notes:
– an updated version of EF Power Tools which allows generating views (and more) directly from Visual Studio version was shipped recently
– view generation in EF6 has been greatly improved so maybe you don’t really need to use pre-generated views?

(Because you read this post you might be interested in this.)


4 thoughts on “EF6 CodeFirst View Generation T4 Template for C# updated for EF6 RTM

  1. […] This can be worked around by generating views at design time (e.g. using EF Power Tools or my T4 templates for generating views) and compiling them into you EF […]


  2. Jok Mak says:

    Having an issue when running the template http://stackoverflow.com/questions/29314872/ef6-view-generator-issue
    Do you have any ideas why?


    • moozzyk says:

      Unfortunately the exception thrown by the T4 template is not very useful. It says: “Retrieve the LoaderExceptions property for more information.” however I don’t think it is possible to do so. The first question is – are you 100% positive you need pre-generated views? There were improvements to view generation in EF6 and pre-generated views help only if you have a big or a very complex model. For small and medium sized models view generation is typically not a problem anymore. I think model building was a bigger problem in EF6. Also, ngen’ing (creative native images) EntityFramework.dll helped mitigate some issues with slow start up time. See this blog post for more details http://blogs.msdn.com/b/adonet/archive/2013/10/17/ef6-rtm-available.aspx.
      With regards to the issue you have – are you using the latest VS update (or really the latest version of EF tools)? If you are, and you are still seeing the issue you might try enabling fusion logging as per instructions here: http://stackoverflow.com/questions/255669/how-to-enable-assembly-bind-failure-logging-fusion-in-net . This should give you information about loading failures that might help resolve the issue. (Remember to turn off fusion logging when you are done with capturing the logs – it slows your machine (especially VS) considerably).
      Finally, you can take a look at another project of mine where the views are pre-generated automatically when needed and stored in a database or a file – https://blog.3d-logic.com/2013/12/14/using-pre-generated-views-without-having-to-pre-generate-views-ef6/
      Hope this helps,


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: