Posts

Showing posts from November, 2015

T4 Templates and the Entity Framework

Code generation isn’t new in Visual Studio. Nearly every visual design surface, from Web Forms to Windows Forms to typed DataSet designers, has transformed shapes into code using code generation behind the scenes. The key phrase is behind the scenes. As developers, we did not always have the control we needed over the code generation process. What is new in Visual Studio is how more frameworks are using T4 Templates for code generation. The frameworks integrating with T4 can give developers complete control over the code generation process. The Entity Framework is one such framework. This paper will discuss how the Entity Framework uses T4 Templates to generate custom code from an ADO.NET Entity Data Model (EDM), and assumes the reader is already familiar with the Entity Framework’s API and designer. We’ll begin with an overview of the T4 technology and see how the technology works. We’ll also look at how we can programmatically consume metadata from an EDM. In the end, we’ll combin