Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you want to use the Entity Frameworks metadata, you need to go looking through the <code>MetadataWorkspace</code> which hangs off the <code>ObjectContext</code>.</p> <p>The starting point is to get the EntityType for your base type, in your case Contact.</p> <p>I have an <a href="http://blogs.msdn.com/alexj/archive/2009/03/26/index-of-tips.aspx" rel="nofollow noreferrer">EF tips series</a> and in <a href="http://blogs.msdn.com/alexj/archive/2009/04/15/tip-13-how-to-attach-an-entity-the-easy-way.aspx" rel="nofollow noreferrer">Tip 13</a> I show an extension method on <code>MetadataWorkspace</code> that gets the <code>EntityType</code> for a particular CLR Type:</p> <pre><code>public static EntityType GetCSpaceEntityType&lt;T&gt;( this MetadataWorkspace workspace); </code></pre> <p>You can use this like this:</p> <pre><code>var contactEntity = ctx.MetadataWorkspace.GetCSpaceEntityType&lt;Contact&gt;(); </code></pre> <p>Once you have this you can look at it's NavigationProperties to find the relationship's and the names you are interested in including:</p> <p>i.e.</p> <pre><code>foreach(var np in contactEntity.NavigationProperties) { Console.WriteLine("Include: {0}", np.Name); Console.WriteLine("... Recursively include "); EntityType relatedType = (np.ToEndMember.TypeUsage.EdmType as RefType).ElementType; //TODO: go repeat the same process... i.e. look at the relatedTypes // navProps too until you decide to stop. } </code></pre> <p>Of course how you decide what you want to Include is up to you. Hope this helps</p> <p>Alex</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