Generating classes from the first EF diagram

When I create a new Entity Data ADO.NET data model in Visual Studio 2012, it gives me a free element for generating code for the EF 5.x DbContext generator. In other words, if I expand my edmx element in Solution Explorer, I see a couple of .tt files that theoretically should create magic .cs files containing my POCO classes and my DbContext class.

My problem is that I cannot convince Visual Studio to create classes. Model1.tt contains an empty Model1.cs, and Model1.Context.tt contains a DbContext object, but it does not contain the DbSet <> collections associated with my objects.

If I remove two .tt elements from my solution, then right-click on the surface of the constructor, select Add Code Generation Element and add the EF 5.x DbContext Generator, then everything will work as it should, and I will get the generated classes.

I checked that the deleted * .tt files are essentially identical to the ones I added.

Any words of wisdom? Is this a mistake, or am I missing something?

Bean

+4
source share
1 answer

Check this one . There is an error in VS2012 that causes this behavior when EDMX is not in the root of the project. Thus, you can use your workaround and add templates manually or manually run your own tool to force the code to be generated as described in the link.

+7
source

All Articles