Friday, 20 July 2012

Add text template to an edmx file

The edmx designer let's you customize your entities and sync the changes for your schema with the database and generates static entities from your edmx. What if you want to add a base class to these entities?

The solution is to attach a text template (TT) to your EDMX file. This will allow you to add features and change the entities common behavior allowing you to write less redundant code in your partial classes implementation.

 Add the text template

Follow these steps to add code generation item :
  1. Open your EDMX designer
  2. Right click in the designer and select Add code generation item.
  3. Select ADO.NET EntityObject Generator
  4. Click ok 
You will see the TT file appears and a corresponding .cs generated file. Now it is possible to add a base class and additional features to your entities.


Download the demo project

No comments:

Post a Comment