EF Power Tools CTP1 Released
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
Last month we announced the RTW of Entity Framework 4.1 (Magic Unicorn Edition). As we worked on the EF 4.1 release we had a series of Community Technology Previews (CTPs) and it was great to have consistent feedback coming in from you all. So, with EF 4.1 released we thought it was time to get some more pre-release stuff in your hands…
Today we are releasing a preview of some Power Tools for EF 4.1 that integrate with Visual Studio. This first preview of the EF Power Tools is focused on providing design-time tools for Code First development.
Where Do I Get It?
EF Power Tools CTP1 is available on the Visual Studio Gallery
You can also install the power tools directly from Visual Studio by selecting ‘Tools –> Extension Manager…’ then searching for “Entity Framework Power Tools” in the Online Gallery.
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 CTP1 is not intended or licensed for use in production. If you have questions please use the “Q & A” tab on the Entity Framework Power Tools Visual Studio Gallery page .
What Does It Add To Visual Studio?
EF Power Tools CTP1 is focused on Code First development and adds some options to context menus in Visual Studio:
When right-clicking on a C# project an ‘Entity Framework’ sub-menu is added:
- Reverse Engineer Code First
This command allows one time generation of Code First to 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.- You will need to have EF 4.1 installed or have added the EntityFramework NuGet package to your project before running reverse engineer.
- The reverse engineer process currently 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.
- In the future we may look at options that allow only minimal mapping to be generated along with the option to use Data Annotations for mapping rather than the fluent API. We would really like to hear you feedback on this.
- 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 App/Web.config 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.
When right-clicking on a file containing a derived DbContext class an ‘Entity Framework’ sub-menu is added:
- 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 can not 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. - Optimize Entity Data Model
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 Code First model then you will need to re-generate the pre-compiled views by running this command again.
Where Are Enums/Spatial/Migrations/…?
Our team is working on many new features including the ones mentioned above. This power tools preview is just one of a series of previews we have planned as we work on the next release. Rest assured, we appreciate that these are very important features and we will be reaching out for your feedback on them.
Andrew Peters & Rowan Miller
ADO.NET Entity Framework
Comments
Anonymous
May 18, 2011
The comment has been removedAnonymous
May 18, 2011
"When right-clicking on a C# project an ‘Entity Framework’ sub-menu is added:" No VB love?Anonymous
May 18, 2011
Great job, very geeky, but really, can you please get the Spatial stuff out so I can finally start to use EF? I'm left to use ado.net with SQL Server 2008 Spatial Data Types to do what I need to do right now and thinking of using NHibernate I guess a lot of other developers are in my same positionAnonymous
May 18, 2011
@smnbss Mindscape's LightSpeed product has supported spatial and has for a couple of years now. And enums. And migrations. Great work guys!Anonymous
May 18, 2011
@smnbss LLBLGen Pro also does support spatial types, enums, db first, model first, generating of DDL SQL migration scripts for some time now. Designer supports EF and NHibernate as well, so you can always go back to EF later when they have added spatial, enums and the like (if you still want to ;))Anonymous
May 18, 2011
Very very very awesome! I was asking for this for long time Thanks!Anonymous
May 18, 2011
Thank you very much. The ADO.NET team wins big time. I would like to ask to add attribute generation to the EDMX designer using PEM.Anonymous
May 18, 2011
hooray for enums and spatial support! Also good acting by Jeff Derstadt on TechEd :DAnonymous
May 18, 2011
System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL)) at VSLangProj.References.Add(String bstrPath) at Microsoft.DbContextPackage.DbContextPackage.ReverseEngineerCodeFirst(Project project)Anonymous
May 18, 2011
@Daniel, Make sure EF4.1 is available in your project. Either download and install it in the GAC or use the NuGet package to add it to your project.Anonymous
May 18, 2011
nice - although you guys should concentrate on migrations (and enums) first...Anonymous
May 18, 2011
Works great with the SQL Server EF provider but not with Devart's Oracle EF provider. My DbContext derived class works with both providers depending on the connection string in my app/web.config. But even with the connection string configured with Devarts Oracle EF provider, the storage xml and DDL generated from the power tools menu options is for SQL Server, not Oracle. I also had the following statements in my OnModelCreating override: if (ConfigurationManager.ConnectionStrings[typeof(MyDbContext).Name].ProviderName == "Devart.Data.Oracle") { modelBuilder.Conventions.Remove<ColumnTypeCasingConvention>(); } which is required to make EF work with Devart's oracle provider. The power tools menu options failed because the connection string could not be found. Would be great if the power tools could work with other providers too.Anonymous
May 18, 2011
Selecting "Optimize Entity Data Model" on a class file that implements DbContext results in the error "Cannot perform runtime binding on a null reference". EntityFramework is referenced in the project and it builds without problems.Anonymous
May 18, 2011
Really nice! >>View Entity Data Model (Read-only) It would be fantastic if you could rearrange the entities in the designer and save the diagram (not entity) data for viewing later. When the code changes it would be really great if you could refresh it. We in the middle of a Code First project at the the moment and found that occasionally it would be great to see a diagram - but the layout of an auto generated one is never much good for anything over 10 tables. ThanksAnonymous
May 18, 2011
So it is preferable to use the "PowerTools" other than "DbContext Template from Database-First" right? Or there is a situation for each one?Anonymous
May 19, 2011
Nice work. Really quickly, I found three things that look like issues to me.
- Schema names are not kept. The schema name from the tables that are reversed are not included in the resulting code first code
- Views get reversed, but exactly like a table. So the first time a Code First 'recreates' the database, the view goes away, but is replaced with a physical table
- Running the reverse engineer a second time causes the connectionstring to be duplicated in the web.cofnig file.
Anonymous
May 19, 2011
The comment has been removedAnonymous
May 19, 2011
@JasonBSteele, you could always create a regular class diagram (or several) from the classes. This way you have at least some sort of overview.Anonymous
May 19, 2011
Microsoft Visual Studio
参数错误。 (异常来自 HRESULT:0x80070057 (E_INVALIDARG))
确定
Anonymous
May 19, 2011
Are there any plans of adding Interface support for POCO classes in future release. what i mean is for my POCO classes i create interfaces and then in USAGE of classes instead of calling concrete class i would like to work with class interfaces. Nhibernate supports this but EF does not. Any plans in next release to Fix this issue.Anonymous
May 20, 2011
Three issues that I see after running Reverse Engineer on a local DB:
- Pluralization fails (or isn't attempted) on tables with an underscore in the name. For example, let's say I have People, Addresses and Person_Addresses tables (the last table joins many addresses to a single person). The reverse engineering functionality creates classes called Person.cs, Address.cs, and Person_Addresses.cs. The last should read Person_Address.cs. The same thing happens for tables named Person_ContactMethods and Person_Identifications.
- Being able to override pluralization prior to actual class creation would be nice. I have another table, called AccruedLeaves; this is created as AccruedLeaf.cs. I'd prefer AccruedLeave.cs.
- Where I have tables with multiple foreign keys pointing to the same field in another table, the navigation properties end up with somewhat confusing generic names. For example, let's say I have two tables, Parties and Relationships, to allow relationships between different parties (let's say one party is a company, and other parties are employees). The table structure looks something like: Parties
PartyID PartyName Relationships
FromPartyID ToPartyID FromRoleType ToRoleType The reverse engineered Party class ends up with properties like Relationships and Relationships1. It seems like there may be a better way to handle this, whether it's using field names or prompting the user for meaningful names during the reverse engineering process when this situation is detected.
Anonymous
May 20, 2011
The comment has been removedAnonymous
May 20, 2011
Please consider generating "partial" classes and consider name your gernerated classes something with *.designer.cs Thankx, HarryAnonymous
May 20, 2011
@Ayub Patel We do plan to look at this in the future, but it’s not scheduled to be part of the next release. @NickS In reality I don’t think it’s possible to build a set of rules that everyone would be happy with. The generated code includes mapping for every column and table name so you can just use ‘F2 refactoring’ in Visual Studio to rename your classes and properties and everything will continue to work correctly. Regarding the cascade delete issue, this is a bug that we will fix in the next preview. We are not overriding the default Code First cascade delete settings for required relationships (cascade delete on). You will need to edit the mapping files to switch off cascade delete on the required relationships. @Harry The ‘Reverse Engineer Code First’ is designed to give you a starting point and you own the code once it is generated, so adding ‘designer’ isn’t really appropriate in this case because the code is not maintained by a designer. Partial sounds like a reasonable request though :)Anonymous
May 22, 2011
with mysql data provider I get: System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.DbContextPackage.DefaultTemplates.MappingTemplate.TransformText() at Microsoft.DbContextPackage.DbContextPackage.ReverseEngineerCodeFirst(Project project) 4.1 ef is installed in the project. dbml generation works otherwise for normal ef.Anonymous
May 22, 2011
I would like to see generated code that obeys the code analysis rules. For example, we shouldn't be seeing setters on collection properties.Anonymous
May 22, 2011
When I right click my class that derives from DbContext and pick any of the options, Visual Studio reports: "A publically constructible type deriving from DbContext could not be found in the selected file.". What's wrong? Snippet: public class MyDatabase : DbContext { }Anonymous
May 23, 2011
@robert We haven’t tested the reverse engineer capabilities with other providers yet. I would be interested to see the schema that is causing the issue though, can you send me a create script for your schema to “rowmil AT microsoft DOT com”. @Jonathan Allen Absolutely, we’ll take care of these sort of things once we get a little further down the release path. @Stian Can you send me a project that reproduces the issue? “rowmil AT microsoft DOT com”Anonymous
May 23, 2011
Great job! Suggestion for future release: Add support to read descriptions from database schema and put them in comments of generated properties.Anonymous
May 25, 2011
Sugestion: Generate classes using T4 templates.Anonymous
May 25, 2011
@Remco Blok EF Power Tools can be used with the Devart providers for Oracle, MySQL, PostgreSQL, and SQLite as well. Please refer to www.devart.com/.../using-entity-framework-power-tools-ctp1-with-oracle-mysql-postgresql-and-sqlite.html .Anonymous
May 26, 2011
Nice tool! But I have some questions about sync with db, in case if some changes appear in database, and in classes we do some changes, how we can sync that changes without losing our code? or what about generate partial classes? ThnaksAnonymous
May 29, 2011
The comment has been removedAnonymous
May 31, 2011
Reverse Engineer Code First doesn't generate working code for tables outside the default schema. Had to add the second Parameter to all this.ToTable("InstancesTable","System.Activities.DurableInstancing"); calls.Anonymous
June 07, 2011
View Entity Data Model command does not work if context-derived class has non-default constructor, for example: public NorthwindContext(string nameOrConnectionString) : base(nameOrConnectionString) { } Error message in Visual Studio toolbar "A publicly construcible type deriving from DbContext could not be found in the selected file".Anonymous
June 12, 2011
This tool does not support DB schemas and is therefore not usable unless everything is in DBOAnonymous
June 16, 2011
One minor bug: the singularization is off when running the reverse code first functionality. My table "testcases" was created in a class "testcas"Anonymous
June 27, 2011
The comment has been removedAnonymous
June 29, 2011
A shout for the people who really really really want to see migration happening. Very annoying to still see this missing for people who actually want to make real products with EF.Anonymous
July 13, 2011
Love the tool, but not working quite right. Getting following error, "Error message in Visual Studio toolbar "A publicly construcible type deriving from DbContext could not be found in the selected file", even when default constructor is present in Derived DbContext: public class ExpenseSampleContext : DbContext { public ExpenseSampleContext() { } ... Any recommendations would be greatly appreciated.Anonymous
July 16, 2011
Dont work with SqlCE4: The mapping and metadata information for EntityContainer no longer matches the information used to create the pre-generated views EF Power ToolsAnonymous
July 23, 2011
I'd like a short overview of what Migrations will cover, can't seem to find a good description on this site. (I know what migration is, just what is the proposed implementation for EF)Anonymous
October 18, 2011
Great, where's the version most VB?Anonymous
January 04, 2012
decimal precision be reduced. SQL Server 2005 SP4,VS2010 SP1,EF Power Tools CTP1 In the Table PortfolioAssetPosition CREATE TABLE [dbo].[PortfolioAssetPosition]( [Id] [bigint] IDENTITY(1,1) NOT NULL, [PortfolioId] [int] NOT NULL, [SecurityId] [bigint] NOT NULL, [Weight] [decimal](18, 12) NULL, [Shares] [decimal](18, 0) NULL, [ClosePrice] [decimal](18, 6) NULL, [CreateDate] [datetime] NULL CONSTRAINT [DF_PortfolioAssetPosition_CreateDate] DEFAULT (getdate()), [CreateUser] varchar COLLATE Chinese_PRC_CI_AS NULL, [UpdateDate] [datetime] NULL, [UpdateUser] varchar COLLATE Chinese_PRC_CI_AS NULL, [Deleted] [tinyint] NULL CONSTRAINT [DF_PortfolioAssetPosition_Deleted] DEFAULT ((0)), The EF build sql is : exec sp_executesql N'insert [dbo].[PortfolioAssetPosition]([PortfolioId], [SecurityId], [Weight], [Shares], [ClosePrice], [CreateDate], [CreateUser], [UpdateDate], [UpdateUser], [Deleted]) values (@0, @1, @2, null, @3, null, @4, @5, @6, null) select [Id] from [dbo].[PortfolioAssetPosition] where @@ROWCOUNT > 0 and [Id] = scope_identity()',N'@0 int,@1 bigint,@2 decimal(18,2),@3 decimal(18,2),@4 nvarchar(50),@5 datetime,@6 nvarchar(50)',@0=31,@1=228906066125,@2=1,@3=5.70,@4=N'',@5=''2012-01-05 10:42:20:983'',@6=N'' the [Weight] [decimal](18, 12) is changed to decimal(18,2)Anonymous
March 05, 2012
Hi, I use the entity framework 4.1 code first and when i do right click reverse engineer code first i got the following error: Exception of HRESULT 0x80070057 (E_INVALIDARG) thanks for your helpAnonymous
March 06, 2012
@Luis - Would you be able to provide a project that reproduces this issue? You can you use the 'Email Blog Author' link at the top to make contact with us.Anonymous
August 13, 2012
Where is the Q&A on the power tools site? We want the reverse engineering to leave out table names alone, and we dont want pluralizing either. For a table called TimeStatus, we want a file called TimeStatus.cs and a DbSet TimeStatus TimeStatus. We get a file called TimeStatu.cs and DbSet TimeStatu TimeStatus and all others are DbSet TableName TableNames. We do not want the s.Anonymous
August 15, 2012
@mbowles - Stack Overflow is the place to go for questions about anything EF related. Pluralization can't be disabled in the current release of the Power Tools. It's definitely a very common request so we'll take care of it in the next release. I don't have a timeframe for the next Power Tools release (our team has been slammed with the EF5 RTM and moving open source). Long term we are looking at moving the Reverse Engineer Code First functionality into the main EF tooling.Anonymous
August 05, 2013
Awesome stuff!!! Thank you very much!