Preview of useful design-time features for DbContext.
When right-clicking on a C# project, the following context menu function is supported:
1) Reverse Engineer Code First - Generates POCO classes, derived DbContext and Code First mapping for an existing database.
Reverse engineer worked on my database of 13 entities that was created model-first in EF 4.0. It even put IsRowVersion() on my timestamp columns!
Note that it automatically downloads the latest entity-framework, which means it will grab an unstable RC version if you didn't explicitly download one first. (The tool should probably honor the user's last settings in Visual Studio's "Manage NuGet Packages" if possible)
Many of the negative reviews complain about things which have nothing to do with this tool. One complains it crashes when you have 1392 tables. That's not what the Entity Framework is for! Another is a problem with source control. Yet another is about generating views.
Great tool, but the reverse engineer needs a dialog to select specific tables, I tested the tool on a data base with 1267 tables and have to wait to much time to generate the classes, and after that, delete all the unnecesary files.
Until you can select individual tables to add, I don't find this very useful.
I am writing a small app to view To-Dos in a database of 100 tables, and have to wait for all of those classes to generate, then deleting all of unused data, is challenging and a waste of my time. Please make these changes.
error : Running transformation: System.NullReferenceException: Object reference not set to an instance of an object.
However I have the solution for anyone else who reads this:
Right click on the project > Entity Framework > Custom Reverse Engineer Templates
This will add a few .tt files into your projet so that you can now change them (and fix the bug!)
- Open Mapping.tt - Search for the line "if (fixedLengthFacet != null && (bool)fixedLengthFacet.Value)" - Replace this with "if (fixedLengthFacet != null && fixedLengthFacet.Value is bool && (bool)fixedLengthFacet.Value)" - Run Entity Framework > Reverse Engineer Code First
This is a great tool. It's still flaky enough to deserve the "Beta" appellate, but the code generated is still a tremendous time-saver for production work.
The biggest feature I'd like to see is the ability to select which tables to generate entities for. I'm using this tool for 1) working on a new app with a lot of churn from the DBA and 2) refactoring an old app. For both, I want to work within bounded contexts that are fairly stable. I don't need to rummage through 100+ files of junk for the bits I don't need.
Even without that feature, this tool is a huge help.
My case is that I have a library (a dll) with my POCO entites. this is a common library.
I also have other library that is the repository that I use to access to the database. This library has the edmx model and the class that implements the repository. From the edmx I create the the myContext.Context.tt file with a list that contains all my entities. I modify the template to use the namespace of my common library with the POCO entities because I want to use this entities, so I delete the myContext.tt file that contains the new entities.
Then I try to use the tolos to pre generate the view, so I right click the edmx file and choose generate view. I set a breakpoint in the the getViewAt to check if the pre generated views are used. however, they are not used.
I also have tried right click in the myContext.Context..cs file and try to generate the view from this file, but in this case I get the following error: "the parameter is invalid. Expcetion HResult: 0x80070057 (E_INVALIDARG))".
So I would like to know how to use the views when I have my POCO entities in a common library.