4

When I create a new ADO.NET Entity Data Model in Visual Studio 2012, it gives me a free EF 5.x DbContext Generator Code Generation Item. In other words, if I expand my edmx item in Solution Explorer, I see a pair of .tt files that, in theory, should magically generate .cs files containing my POCO classes and my DbContext class.

My problem is that I can't convince Visual Studio to actually create the classes. Model1.tt contains an empty Model1.cs, and Model1.Context.tt contains a DbContext object but it doesn't contain the DbSet<> collections associated with my entities.

If I remove the two .tt items from my solution, then right-click the designer surface, select Add Code Generation Item, and add an EF 5.x DbContext Generator then everything works like it should and I get the generated classes.

I've verified that the *.tt files that I removed are, in fact, identical to the ones that I've added back in.

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

Bob

2

1 Answer 1

7

Check this. There is a bug in VS2012 which causes this behavior when EDMX is not in the project root. So you can either use your workaround and add templates manually or you must manually trigger custom tool to force the code generation as described in the link.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.