Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It appeared much easier than I thought. If anybody is interested there is a t4 template for recursive scan through entity tree:</p> <pre><code>&lt;#@ template language="C#" debug="false" hostspecific="true"#&gt; &lt;#@ include file="EF.Utility.CS.ttinclude"#&gt;&lt;#@ output extension=".cs"#&gt;&lt;# // Copyright (c) Microsoft Corporation. All rights reserved. CodeGenerationTools code = new CodeGenerationTools(this); MetadataLoader loader = new MetadataLoader(this); CodeRegion region = new CodeRegion(this, 1); MetadataTools ef = new MetadataTools(this); string inputFile = @"D:\Projects\Empresa\CTM_Empresa\trunk\CTM.Empresa.Logic\DataModel\CTM.Empresa.Database.edmx"; string entityName = @"Email"; bool printNavigationLists = false; MetadataWorkspace metadataWorkspace = null; bool allMetadataLoaded = loader.TryLoadAllMetadata(inputFile, out metadataWorkspace); EdmItemCollection ItemCollection = (EdmItemCollection)metadataWorkspace.GetItemCollection(DataSpace.CSpace); string namespaceName = code.VsNamespaceSuggestion(); EntityFrameworkTemplateFileManager fileManager = EntityFrameworkTemplateFileManager.Create(this); RecursiveEntityProcessor.code = code; RecursiveEntityProcessor.ItemCollection = ItemCollection; RecursiveEntityProcessor.metaData = ef; // Emit Entity Types foreach (EntityType entity in ItemCollection.GetItems&lt;EntityType&gt;().Where(it =&gt; it.Name == entityName)) { fileManager.StartNewFile(entity.Name + ".cs"); var result = new List&lt;PropertyCustomData&gt;(); RecursiveEntityProcessor.GetEntityPropertyNames(result, entity.Name , 2 , ""); //WriteEntityTypeSerializationInfo(entity, ItemCollection, code, ef); #&gt; &lt;#=Accessibility.ForType(entity)#&gt; &lt;#=code.SpaceAfter(code.AbstractOption(entity))#&gt;class &lt;#=code.Escape(entity)#&gt;&lt;#=code.StringBefore(" : ", code.Escape(entity.BaseType))#&gt; { &lt;# foreach (PropertyCustomData property in result) { #&gt; /// &lt;summary&gt; /// Gets or sets &lt;#=code.Escape(property.PropertyName)#&gt;. /// &lt;/summary&gt; &lt;#=Accessibility.ForProperty(property.PropertyDefenition)#&gt; &lt;#=code.Escape(property.PropertyDefenition.TypeUsage)#&gt; &lt;#=code.Escape(property.PropertyName)#&gt; { get; set; } &lt;# } }#&gt; } &lt;#+ public class PropertyCustomData { public EdmProperty PropertyDefenition { get; set; } public string PropertyName { get; set; } } public static class RecursiveEntityProcessor { public static CodeGenerationTools code; public static EdmItemCollection ItemCollection; public static MetadataTools metaData; public static EntityType FindByName(string entityName) { return ItemCollection.GetItems&lt;EntityType&gt;().Single(it =&gt; it.Name == entityName); } public static void GetEntityPropertyNames(IList&lt;PropertyCustomData&gt; result, string entityName, int recursiveDepth, string currentPrefix, bool canPrintPrimaryKeys = true) { if (recursiveDepth &gt; 0 ) { EntityType entity = FindByName(entityName); foreach (EdmProperty edmProperty in entity.Properties.Where(p =&gt; p.TypeUsage.EdmType is PrimitiveType &amp;&amp; p.DeclaringType == entity)) { if (metaData.IsKey(edmProperty) &amp;&amp; !canPrintPrimaryKeys) { continue; } result.Add(new PropertyCustomData { PropertyDefenition = edmProperty, PropertyName = currentPrefix + code.Escape(edmProperty) }); } foreach (NavigationProperty navProperty in entity.NavigationProperties.Where(np =&gt; np.DeclaringType == entity)) { if (navProperty.ToEndMember.RelationshipMultiplicity != RelationshipMultiplicity.Many) { string childEntityName = navProperty.ToEndMember.GetEntityType().Name; GetEntityPropertyNames(result, childEntityName, recursiveDepth - 1, currentPrefix + code.Escape(navProperty), false); } } } } } #&gt; </code></pre> <p>this template produces code like in last example of my question.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload