Wednesday, November 30, 2011

T4 templates

T4 templates are .NET code generation tools. A T4 file has a .tt extension which one may right-click upon and pick "Run Custom Tool" to make the magic happen. Inside the .tt file is C# markup driving the magic. In our app we are using a T4 template to sniff the scope of an Entity Framework .edmx file and then render our corresponding NHibernate mapping files. This trick allows us to use the 1% of Entity Framework that is good along side of NHibernate.

   

Byron latches onto the .edmx like so:

string inputFile = @"ObjectModel.edmx";

   

Byron loops through entities in the .edmx like so:

foreach (EntityType entity in itemCollection.GetItems<EntityType>().OrderBy(e => e.Name))

No comments:

Post a Comment