Simply put, T4 templates can generate classes for you (and other files) based on some input, such as the Entity Framework model. This is very convenient in cases where you need to create many classes (for example, classes for all objects of the large Entity Framework model) with identical functions. Then the T4 template simply does the job and automatically updates the created classes if the input changes (you can run the "Custom Tool" on the input file to also run the T4 template).
The T4 template can (of course) create partial classes so you can add members (to other parts of the class you are creating). That way, you can add functionality that is not overwritten when the template recreates classes.
The T4 templates that generate the POCO classes (the default for EF in .NET 4.5) based on the EF model are a great example of the good use of T4 templates. Another example is the T4 template, which creates the base classes of the view model (for MVVM) for all entity classes of the EF model.
source share