Share via


EF Power Tools Beta 2 Available

 


The information in this post is out of date.

Visit msdn.com/data/ef for the latest information on current and past releases of EF.

For EF Power Tools see https://msdn.com/data/jj593170


 

The Entity Framework Power Tools provide additional design-time tools in Visual Studio to help you develop using the Entity Framework. Today we are releasing Beta 2 of the Power Tools.

 

Where do I get it?

The Entity Framework Power Tools are available on the Visual Studio Gallery.

You can also install them directly from Visual Studio by selecting 'Tools -> Extension Manager...' then searching for "Entity Framework Power Tools" in the Online Gallery.

If you encounter an error while upgrading from an older version of EF Power Tools, you will need to uninstall the older version first then install EF Power Tools Beta 2. This is due to a bug in Visual Studio that blocks the upgrade because the certificate used to sign Beta 2 has a different expiry date than Beta 1.

 

What's new in Beta 2?

Beta 2 improves the quality of the previous release, and also adds new functionality.

  • Code generated by reverse engineer can be customized using T4 templates.
  • Fixed many reverse engineer bugs relating to the code that we generate.
  • Generate Views (formerly Optimize Entity Data Model) is now available for database-first and model-first. Right-click on an EDMX file to access the command.
  • Enhanced DbContext and database discovery. We fixed many bugs around how we locate your DbContext and the database it connects to.

For a complete list of the features included in the Power Tools see the What does it add to Visual Studio section.

 

Compatibility

The Power Tools are compatible with Visual Studio 2010 and Entity Framework 4.2 or later.

You can also install the Power Tools on Visual Studio 11 Beta, but you may receive the error "A constructible type deriving from DbContext could not be found in the selected file." This is caused by a bug in the Visual Studio 11 unit test tools where an older version of EntityFramework.dll is being loaded. We are working closely with that team to resolve the issue. As a workaround, you can delete the HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0_Config\BindingPaths\{BFC24BF4-B994-4757-BCDC-1D5D2768BF29} registry key. Be aware, however, that this will cause the Unit Test commands to stop working. Thank you, early adopters, for your superhuman patience with prerelease software.

 

Support

This release is a preview of features that we are considering for a future release and is designed to allow you to provide feedback on the design of these features. EF Power Tools Beta 2 is not intended or licensed for use in production.

If you have a question, ask it on Stack Overflow using the entity-framework tag.

 

What does it add to Visual Studio?

EF Power Tools Beta 2 is for Code First, model-first, and database-first development and adds the following context menu options to an 'Entity Framework' sub-menu inside Visual Studio.

When right-clicking on a C# project

ProjectMenu

  • Reverse Engineer Code First
    This command allows one-time generation of Code First mappings for an existing database. This option is useful if you want to use Code First to target an existing database as it takes care of a lot of the initial coding. The command prompts for a connection to an existing database and then reverse engineers POCO classes, a derived DbContext, and Code First mappings that can be used to access the database.
    • If you have not already added the EntityFramework NuGet package to your project, the latest version will be downloaded as part of running reverse engineer.
    • The reverse engineer process by default produces a complete mapping using the fluent API. Items such as column name will always be configured, even when they would be correctly inferred by conventions. This allows you to refactor property/class names etc. without needing to manually update the mapping.
      • The Customize Reverse Engineer Templates command (see below) lets you customize how code is generated.
    • A connection string is added to the App/Web.config file and is used by the context at runtime. If you are reverse engineering to a class library, you will need to copy this connection string to the configuration file of the consuming application(s).
    • This process is designed to help with the initial coding of a Code First model. You may need to adjust the generated code if you have a complex database schema or are using advanced database features.
    • Running this command multiple times will overwrite any previously generated files, including any changes that have been made to generated files.
  • Customize Reverse Engineer Templates
    Adds the default reverse engineer T4 templates to your project for editing. After updating these files, run the Reverse Engineer Code First command again to reverse engineer POCO classes, a derived DbContext, and Code First mappings using your project's customized templates.
    • The templates are added to your project under the CodeTemplates\ReverseEngineerCodeFirst folder.

 

When right-clicking on a code file containing a derived DbContext class

ItemMenu

  • View Entity Data Model (Read-only)
    Displays the Code First model in the Entity Framework designer.
    • This is a read-only representation of the model; you cannot update the Code First model using the designer.
  • View Entity Data Model XML
    Displays the EDMX XML representing the Code First model.
  • View Entity Data Model DDL SQL
    Displays the DDL SQL to create the database targeted by the Code First model.
  • Generate Views
    Generates pre-compiled views used by the EF runtime to improve start-up performance. Adds the generated views file to the containing project.
    • View compilation is discussed in the Performance Considerations article on MSDN.
    • If you change your model then you will need to re-generate the pre-compiled views by running this command again.

 

When right-clicking on an Entity Data Model (*.edmx) file

  • Generate Views
    This is the same as the Generate Views command above except that, instead of generating pre-compiled views for a derived DbContext class, it generates them for your database-first or model-first entity data model.

 

Brice Lambson
ADO.NET Entity Framework

Comments

  • Anonymous
    April 09, 2012
    Do Generate Views now supports SQL CE? Or at least ignore generated views allowing me to run the same code with SQL server and CE?

  • Anonymous
    April 09, 2012
    Didn't checked it out yet, but does it have an option to turn off pluralization?

  • Anonymous
    April 09, 2012
    Is it possible generate reverse engineer for some tables only ? For example I choose what table I need to generate ?

  • Anonymous
    April 09, 2012
    Answering my question. Doesn´t work with SQL CE. There is any way to disable Generated Views when using SQLCE?

  • Anonymous
    April 09, 2012
    Have it generate an OData service automatically too...

  • Anonymous
    April 10, 2012
    The comment has been removed

  • Anonymous
    April 10, 2012
    I'm trying the 'Customize Reverse Engineer Templates' option and i get and error after the default templates have been added to my project, missing reference to the EfTextTemplateHost ? Am i missing something...

  • Anonymous
    April 10, 2012
    @Brice Lambson Thanks for clearing that. Once again great tool, thanks for all the efforts.

  • Anonymous
    April 10, 2012
    The comment has been removed

  • Anonymous
    April 10, 2012
    Update to my earlier post on 'Customize Reverse Engineer Templates', I restarted visual studio 11 beta and rebuilt my project and the error has now gone. Thanks for the reverse DB options in particular, great piece of functionality.

  • Anonymous
    April 10, 2012
    @Lombo, This error is just an unfortunate side effect of adding the .tt files to the project; it is safe to ignore. As you found, re-opening the project will make the error go away. @ckaut, I'm affraid that the current Power Tools don't offer much help here. There's a great MSDN article on how to do this for database-first and model-first at msdn.microsoft.com/.../bb896240.aspx.

  • Anonymous
    April 10, 2012
    Reverse Engineer Code First is excellent! Thank you. But any chance to include option for "normalize" lowercase naming in legacy databases  first_name = FirstName, id = Id etc. I use "Customize Reverse Engineer Templates" and do  some changes suggested by Dan Pettersson in stackoverflow.com/.../t4-fieldname-in-camelcase-without-underscore but it would be nice to this was in core tool.

  • Anonymous
    April 11, 2012
    @Felipe Fujiy – This looks like a bug, I’ve opened a work item for us to fix it. @Jeff – That’s an interesting idea, feel free to suggest it on our user voice site and we’ll see how many votes it gets (http://ef.mswish.net). @andrex – We’re going to suggest that folks use custom templates for this kind of thing at the moment. In the future we’ll look at taking the most  common customizations and adding them into the tool itself.

  • Anonymous
    April 12, 2012
    The comment has been removed

  • Anonymous
    April 13, 2012
    @Dennis Wanke

  1. I've added a bug to our backlog to look at this.
  2. Is there a scenario that is broken by these all being public in the edmx? We've typically seen these tools used to view the model and debug it, but if there is a scenario where the access modifier in the xml matters then we can look at fixing it.
  3. If your context doesn't have a default constructor then you can add an implementation of IDbContextFactory<TContext> to the same project as the context. This will let the Power Tools, Migrations, etc. know how to construct your context.
  • Anonymous
    April 15, 2012
    The comment has been removed

  • Anonymous
    April 16, 2012
    @Robert Lange - Any chance you can send me a solution that reproduces issue #1? Issue #2 is on our backlog and we'll try and get it working for the next release.

  • Anonymous
    April 16, 2012
    @Robert Lange - BTW you can use the 'Email Blog Author' link at the top right of this page, I'll reply so you can attach the project.

  • Anonymous
    April 19, 2012
    @Rowan - thank you for your reply. The scenario (#2) is just the same – to visualize and validate the code-based model. The problem is, we have pay close attention on the access modifiers of all the properties, entities, sets and containers in all the models throughout the entire codebase (because it’s actually a library). So the tool just doesn’t help us with it, though it could. The other scenario I could imagine is switching from existing code-first to model-first by taking the generated edmx as basis. The more precise the generated edmx would reflect the code-model, the fewer manual adjustments would be required in that case. Regarding #3. As mentioned in my original post, the IDbContextFactory interface is not always a good option, especially in library code, since it just can’t provide the desired level of encapsulation. One still can cast and call Create() just as easy as a public constructor. On the other hand, by adding the ability to call non-public constructors you just would make the tool one step better without violating any security considerations, since everything happens in design-time only. And there is no extra implementation costs in doing it - so why not to? Dennis

  • Anonymous
    April 20, 2012
    @Dennis Wanke - #3 makes sense, I was missing that you had a default ctor but it just wasn't public. I've added items to our backlog for both these issues.

  • Anonymous
    April 30, 2012
    A useful tool. I'm not sure I like the idea of having to maintain two files for an entity; the POCO class and the mapping class. A maintenance programmer may forget about the mapping class. Is an option to include DataAnnotations in the POCO class rather than have attributes in a separate mapping class an option being considered for a future version?

  • Anonymous
    May 01, 2012
    @Phil Fresle - Yes, absolutely. Because the templates are editable it would be possible to do this yourself now (although it wouldn't be super easy). We do plan to have a data annotation option included in the Power Tools in the future though.

  • Anonymous
    May 02, 2012
    Thanks very much for this! This is getting us one step closer to fully adopting code-first, and we are really loving it, and getting a quick overview is superb. I was even more excited as I first actually misread about creating views as the only feature missing from code-first for me is creating indexed views. Is this in the roadmap maybe? Any resources on helping us with indexed views and code first? It is easy to map a view created using other means but what about initializing a database/migrations? Any place I can focus on this?

  • Anonymous
    May 02, 2012
    @Mike B - Migrations would be the easiest way to do this. When you scaffold a migration there will be a CreateTable call but you can remove this call and replace it with a call to Sql that specifies the SQL to create the view. Code First will then happily access the view (albeit thinking that it is a table).

  • Anonymous
    May 02, 2012
    The comment has been removed

  • Anonymous
    May 03, 2012
    The comment has been removed

  • Anonymous
    May 03, 2012
    I am getting the error "A constructible type deriving from DbContext could not be found in the selected file." even in Visual Studio 2010, using entity 4.3.1

  • Anonymous
    May 04, 2012
    @Darksome - Does you context have a default (parameterless) constructor? If not, you'll need to add a class that implements IDbContextFactory to you project (this lets tooling know how to create an instance of your context).

  • Anonymous
    May 09, 2012
    The comment has been removed

  • Anonymous
    May 09, 2012
    The comment has been removed

  • Anonymous
    June 04, 2012
    Meus amigos quando ira sair a versão para VB?

  • Anonymous
    June 05, 2012
    @isNIL - We will include a VB.NET version in a future release. It would be a bit of work but you can customize the code generation templates in the existing release to generate VB.NET. Here is an example of customizing the templates - romiller.com/.../customizing-reverse-engineer-code-first-in-the-ef-power-tools.

  • Anonymous
    June 18, 2012
    In VB how can I rename a foreign key of a relationship type TPT?

  • Anonymous
    June 20, 2012
    @isNIL - Are you wanting to rename the foreign key in one of the derived tables that points back to the main table? Unfortunately this isn't currently possible, they primary key of the main table and the primary/foreign key of the derived tables all need to have the same name.

  • Anonymous
    June 27, 2012
    The comment has been removed

  • Anonymous
    June 28, 2012
    The exact error is The type 'System.Data.Spatial.DbGeography' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Data.Entity.ModelConfiguration.Configuration.StructuralTypeConfiguration<TStructuralType>.Property<T>(System.Linq.Expressions.Expression<System.Func<TStructuralType,T>>)'

  • Anonymous
    July 05, 2012
    @Satish – Is your application targeting .NET 4.5? To use Spatial data types you need to be targeting .NET 4.5. Note: If you retarget the application to .NET 4.5 you will also need to uninstall and reinstall the EntityFramework NuGet package to get the .NET 4.5 version of the EntityFramework assembly (which includes spatial support).  

  • Anonymous
    July 06, 2012
    I used the Reverse Engineer Code First option applied to a SQL Server Express file and that works fine (really nice!) but when I use it applied to a Compact Edition file (both 3.5 and 4.0) I got the following exception: System.ArgumentException: The modelEntityContainerName parameter '........sdfContext' contains characters that are not valid.   at System.Data.Entity.Design.EntityModelSchemaGenerator..ctor(EntityContainer storeEntityContainer, String namespaceName, String modelEntityContainerName)   at Microsoft.DbContextPackage.Handlers.ReverseEngineerCodeFirstHandler.ReverseEngineerCodeFirst(Project project) Is this a known bug?

  • Anonymous
    July 08, 2012
    @Vincent - We actually haven’t had that bug reported before, I've added it to our backlog to fix in the next release. The issue appears to be that we use the database name as the context/container name, but in this scenario that includes the full path to the sdf file which needs to be trimmed and/or escaped.

  • Anonymous
    July 16, 2012
    Rowan, do  you have any idea for the next version of Power Tools? I really need the dialog to choose which tables should import, my database have 3k tables+views(including 300 views used by replication) and I just need 300 of them. Importing all tables delays 2 hours, I can´t wait soo long to get a new table. Thx! You guys are doing a very great job!

  • Anonymous
    July 17, 2012
    The comment has been removed

  • Anonymous
    August 10, 2012
    I'm looking to better understand why Power Tools is not choosing to generate partial classes. As directed, I've posted my question to StackOverflow (stackoverflow.com/.../why-are-classes-generated-by-ef-power-tools-not-partial). The only answer offered is a suggestion as to changing templates so as to make them partial. I wouldn't want to do that without understanding why things are as they are. Similar question as regards implementing a Repository Pattern. It appears to be gospel - program to the interface. So if I'm using PT to gen up my POCOs based on my db, why are you not also generating abstract interfaces? thx

  • Anonymous
    August 15, 2012
    @am.steve - I followed up on your Stack Overflow question.

  • Anonymous
    November 08, 2012
    Is there documentation on how to customize the TT files?  I'd like to have the tool generate the model classes in the root of my project.  My project is called Models and having another model folder nested inside it looks kind of silly.  Not a big deal, it's mostly my problem, thanks for the tool!

  • Anonymous
    November 09, 2012
    @Dirk, Unfortunately, there is currently no way to change the name of the output folder. Once the files are generated however, you are free to modify/move them however you like.

  • Anonymous
    November 09, 2012
    @Dirk use this TemplateManager instead: www.databinding.net/.../t4-entityframworktemplatefilemanager-durch-den-templatefilemanager-ersetzen.html With the help of this manager you can also generate files into a different project.

  • Anonymous
    November 29, 2012
    Hi is this compatible with VS2012 Update 1?  I just tried to Reverse Engineer Code First from an existing database and got this error: One or more errors occurred while processing template 'Entity.tt'. C:Program Files (x86)Microsoft Visual Studio 11.0Common7IDEExtensionsMicrosoftEntity Framework ToolsTemplatesIncludesEF.Utility.CS.ttinclude(1,4) : error : A processor named 'T4VSHost' could not be found for the directive named 'CleanupBehavior'. The transformation will not be run.  The following Exception was thrown: System.InvalidOperationException: Cannot find processor for directive 'T4VSHost'.   at Microsoft.DbContextPackage.Utilities.EfTextTemplateHost.Microsoft.VisualStudio.TextTemplating.ITextTemplatingEngineHost.ResolveDirectiveProcessor(String processorName)   at Microsoft.VisualStudio.TextTemplating.Engine.ProcessCustomDirectives(ITextTemplatingEngineHost host, TemplateProcessingSession session, IEnumerable`1 directivesToBeProcessed)

  • Anonymous
    December 03, 2012
    @Paul I'm having the same problem after updating to Update 1. Of course this has been in beta with no new updates for a long time.

  • Anonymous
    December 04, 2012
    The comment has been removed

  • Anonymous
    December 05, 2012
    Getting "Not implemented (Exception from HRESULT: 0x80004001 (E_NOTIMPL))" error when I Right click DBContext inherited file and select  "View Entity Data Model (Read Only)" Visual Studio 2012 Ultimate

  • Anonymous
    December 11, 2012
    Will this be fixed to work with vs2012?  Getting error "A constructible type deriving from DbContext could not be found in the selected file."  C'mon guys ... vs2012 has been released for a couple months now!

  • Anonymous
    January 15, 2013
    I'm also getting the "A constructible type deriving from DbContext could not be found in the selected file." error in VS 2012. I'm willing to try the workaround but my registry does not contain the key "{BFC24BF4-B994-4757-BCDC-1D5D2768BF29}" in "HKEY_CURRENT_USERSoftwareMicrosoftVisualStudio11.0_ConfigBindingPaths". What else can I do?

  • Anonymous
    January 16, 2013
    @John - We're putting together a refresh of the Power Tools at the moment that will address this issue. @Walt Daniels @MdeJ - There was a bug causing that error in the pre-RTM versions of VS2012. If you are seeing it in the RTM version could you start up a StackOverflow issue using the 'entity-framework' tag with details about your project setup etc.

  • Anonymous
    January 16, 2013
    @RowanMiller @Walt Daniels: I've created a question on stackoverflow: stackoverflow.com/.../a-constructible-type-deriving-from-dbcontext-could-not-be-found-in-the-selected

  • Anonymous
    January 17, 2013
    @MdeJ - Thanks, we're taking a look at the issue now.

  • Anonymous
    January 17, 2013
    Parametro non corretto.(Eccezzione da HRESULT:0x80070057(E_INVALIDARG)) ? tanks.

  • Anonymous
    January 18, 2013
    @franck - Would you be able to start up a StackOverflow (http://stackoverflow.com) thread (using the entity-framework tag) with more details about your project setup and when you are seeing the issue.

  • Anonymous
    March 10, 2013
    I would like to create a Knockout version of the reverse engineer tool. Is anyone already doing this?

  • Anonymous
    March 12, 2013
    The comment has been removed