I am working with EF6 and want to add a summary comment to the classes generated by the t4 template. After some hacking time, I managed to do this by downloading the EDMX file and using XPath to find what I needed.
var xmlContent = XDocument.Load(textTransform.Host.ResolvePath(inputFile));
var edmxNavigator = xmlContent.CreateNavigator();
XmlNamespaceManager nsMgr = new XmlNamespaceManager(edmxNavigator.NameTable);
nsMgr.AddNamespace("edmx", "http://schemas.microsoft.com/ado/2009/11/edmx");
nsMgr.AddNamespace("store", "http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator");
nsMgr.AddNamespace("ssdl", "http://schemas.microsoft.com/ado/2009/11/edm/ssdl");
nsMgr.AddNamespace("cs", "http://schemas.microsoft.com/ado/2009/11/mapping/cs");
foreach (var entity in typeMapper.GetItemsToGenerate<EntityType>(itemCollection))
{
fileManager.StartNewFile(entity.Name + ".cs");
BeginNamespace(code);
var mappingAttribute = edmxNavigator.SelectSingleNode("/edmx:Edmx/edmx:Runtime/edmx:Mappings/cs:Mapping/cs:EntityContainerMapping/cs:EntitySetMapping/cs:EntityTypeMapping[@TypeName=\"" + entity.FullName + "\"]/cs:MappingFragment/@StoreEntitySet", nsMgr);
var entitySet = edmxNavigator.SelectSingleNode("/edmx:Edmx/edmx:Runtime/edmx:StorageModels/ssdl:Schema/ssdl:EntityContainer/ssdl:EntitySet[@Name=\"" + mappingAttribute.Value + "\"]", nsMgr);
var actualTableName = (entitySet.SelectSingleNode("@Table") ?? entitySet.SelectSingleNode("@Name")).Value;
var actualSchemaName = (entitySet.SelectSingleNode("@Schema", nsMgr) ?? entitySet.SelectSingleNode("@store:Schema", nsMgr)).Value;
#>
<#=codeStringGenerator.UsingDirectives(inHeader: false)#>
<#=codeStringGenerator.EntityClassOpening(entity)#>
source
share