Sneak Peek – Using Code Generation Templates with the Entity Framework 4.0Entity framework 4.0'ın en önemli yeniliklerinden biri olan POCO entity desteği. Özellikle EF 3.5 ile oluşturulan Entity Model ve onunla oluşan entityler, servislerde serialization problemlerine neden olmaktaydı ki nedeni entity objesinin üzerinde EF'ye ait relation gibi attribute'ların olmasıydı. İşte tam bu noktada EF 4.0 imdada yetişiyor. Ancak EF 4.0 ile POCO Entity leri oluşturmak için manuel bi kaç değişiklik gerekiyo ve Entitylerin oluşması için de T4 template generator'ın kullanılması gerek. Neyse ki bu vs 2010 template'lerinde var ve Edmx Designer'dan çağrılabiliyo. Detaylı bilgi için orjinal döküman linki aşağıdadır.
Published 19 May 09 01:42 PM | dpblogs
In the first version of the Entity Framework code generation was implemented internally using CodeDom. The Entity Framework APIs provided some hooks for customizing the generation, but customizing was tricky, relatively inflexible and wasn’t integrated into Visual Studio.
In .NET 4.0 all these limitations go away.
The Entity Framework now leverages T4, Text Template Transformation Toolkit, which makes customizing Code Generation easy, flexible and powerful, and the experience is also fully integrated into Visual Studio.
T4 itself is very simple, in fact you can try it out in Visual Studio 2008 today if you want. T4 provides a clean way of interleaving control logic and references to variables with output text, that is reminiscent of the techniques used widely in web server programming (for those familiar with old-school ASP or ASP.NET MVC views it will look vaguely familiar).
Out of the box the Entity Framework will ship with two T4 templates, both of which will produce EntityObject derived Entities. One in VB that produces VB code, and one in C# that produces, yes you guessed it, C# code.
Orjinal yazı için...