ilivewithian
ilivewithian

Reputation: 19702

Entity Framework 4 Code Generation Item Ignoring Custom Tool Namespace

I have a project that runs off a model first entity framework edmx file. I've set the custom tool namespace so that the entities end up in the namespace I want them in. This has worked fine for a while.

I now need to customise the generated code, to that end I have added a code generation item, but the code that this generates by default ignores the custom tool namespace.

Apart from the fact I can edit the tt file, what else is different about the code generation items? Also, any thoughts on how to correct the default code generation item so that it respects the custom tool namespace?

Upvotes: 11

Views: 2847

Answers (3)

gxtaillon
gxtaillon

Reputation: 1066

Change the project's default namespace and rebuild your project.

Upvotes: -1

Yakimych
Yakimych

Reputation: 17752

The easiest solution would be to edit the .tt file.

You need to find

string namespaceName = code.VsNamespaceSuggestion();

Then you can replace it with your custom namespace:

string namespaceName = "YourCustomNamespace";

Upvotes: 3

Slappy
Slappy

Reputation: 4092

If you inspect the TT template file you will see a property (in the properties window) that specifies custom tool namespace. Set your namespace here and the template should use this in its code generation, note this is on the TT file, you will need to do this for all TT files you use for your EDMX generation. It does not use the one specified in the EDMX file.

The fix may rectify this behaviour, but don't be scared to dive into the TT. I have a post detailing some changes you may want to make.

http://slappyza.wordpress.com/2010/08/08/getting-the-entity-framework-to-generate-an-interface-for-mocking/

I also spotted a couple of other issues with the VB version. Not sure if they have been fixed.

http://slappyza.wordpress.com/2010/08/03/bug-in-the-ado-net-entity-framework-poco-generator/

Upvotes: 6

Related Questions