Share via


Entity Framework FAQ: Code Generation

 
[[articles:Entity Framework FAQ|Back to EF FAQs Table of Contents]] 

How can I add custom attributes to my generated classes? What is the extensibility story in the Entity Framework for more advanced code generation scenarios

In Visual Studio 2010, the EF uses the Textual Transformation Template Toolkit (T4) code generator that is a part of Visual Studio. Use T4 templates with the ADO.NET Entity Data Model Designer to customize generated data classes. For more information, see How to: Customize Object-Layer Code Generation.

Visual Studio 2010 does not have a built-in T4 editor. There are third-party tools, however, that help with syntax highlighting, IntelliSense, etc. Some options:

In EF 3.5 SP1, the code generation system in the Entity Framework is not nearly so flexible as T4 templates, but it is built on top of a public API that you can call to have finer-grained control over the code generation process. See the EF codegen events for fun and profit blog post for more details. You can also fit these customizations into Visual Studio's extension mechanisms. For more information, see SampleEDMXCodegenerator Sources.

Is there any way to use public, easily modifiable templates for EF code generation

T4 templates are available and can be used with the ADO.NET Entity Data Model Designer to customize generated data classes. The following two templates are included with Visual Studio:

You can also download ADO.NET POCO Entity Generator Template from the Visual Studio Gallery.

The How to: Customize Object-Layer Code Generation topic describes how to use the ADO.NET Entity Data Model Designer and text templates to customize the generation of object context and entity classes (object-layer code).

[[articles:Entity Framework FAQ|Back to EF FAQs Table of Contents]]