Select the “ADO.NET EntityObject Generator” from the Add New Item dialog
Note: The specific instructions below only work for the standard EntityObject Generator, and will not apply directly to the Self-Tracking Entities template. If you wish to use Self-Tracking entities, the instructions in this post should be sufficient to customize the template yourself.
Now you should have a new EfModel.tt file in your project. This is the T4 template that the EDMX designer will use to generate the classes that represent your EDMX model.
Open the newly created EfModel.tt file.
From here, you can customize the template yourself (instructions are provided in Step 3b, or simply download the T4 template that I have provided in Step 3a)
To suppress code analysis, you need to decorate each class definition with a
[GeneratedCode] attribute, as follows:
You can use the standard Visual Studio Find dialog to find all instances where classes are being generated. In the Template that I am using (The one that shipped with Visual Studio 2010 Beta 2) there were 3 places to decorate the code.
Following is a snippet from my modified ObjectContext generation.
/// <summary> /// <#=SummaryComment(container)#> /// </summary><#=LongDescriptionCommentElement(container, region.CurrentIndentLevel)#> [global::System.CodeDom.Compiler.GeneratedCode("EdmxTool", "126.96.36.199")] <#=Accessibility.ForType(container)#> partial class <#=code.Escape(container)#> : ObjectContext
Repeat this process for the 3 remaining class definitions by using the standard Find… dialog. I found it easiest to search for the text “partial class”
Open the EDMX designer and Ctrl+S to save it.
If all goes correctly, the T4 template should kick into action and a new .cs file should be created. This .cs file includes the actual generated code based on your EDMX model and your T4 template. As always with generated code don’t attempt to modify it directly, since the next time you (or someone else) saves the edmx file it will overwrite any changes you made.
Lastly, one final benefit of all of this is that you can make any changes in the T4 template to fully customize how your entities are generated from now on.