EF resolve navigation property after manual attach
<p>I'm using Entity Framework.  I've attached a POCO object representing an entity in the DB to my dbcontext using:</p>

<pre><code>var entity = new MyEntity() { ID = 1, AnotherItemID = 10 };
context.Set&lt;T&gt;().Attach(entity);
</code></pre>

<p>So far so good.  I can access the set and work with the entity I've added.  It's added in the Unchanged state.  However, it is only a POCO and not a Proxy.  Therefore, when I try to access a navigation property, e.g. myEntity.AnotherItem, I just get a null back.</p>

<p>Does anyone know if there is a way to have EF resolve navigation properties for POCO classes attached in this way?  Or of a way to cast the POCO to a proxy class?</p>

<p>Thanks</p>

<p><strong>Update</strong>
There are two ways to solve this (of course there may be others too!).  One is the Explicit Loading option in the answer below.  The other way, which allows lazy loading to work, is to use the DBSet Create method rather than the POCO new keyword when creating entities to be attached.  More info about that here:</p>

<p><a href="https://stackoverflow.com/questions/9695006/ef4-3-code-first-mvc-lazy-loading-after-attaching-in-post-action">EF4.3 Code-First, MVC, Lazy Loading After Attaching in POST Action</a></p>