title: Entity Framework: how to do correct "Include" on custom type
body: <p>Suppose we have 2 types, mapped to a Database via EF 4.</p>
  
  <pre><code>Schedule 1.....1 Visit
  </code></pre>
  
  <p>Also, we have third custom view type</p>
  
  <pre><code>public class ScheduleView
  {
      public Schedule Schedule { get; set; }
      public Visit Visit { get; set; }
  }
  </code></pre>
  
  <p>So we can write the join query </p>
  
  <pre><code>var query = Context.Schedule.Join(Context.Visit
  ,/*Schedule join key definition*/,/*Visit join key definition*/,
  (scheduleView, visit) =&gt; new ScheduleView {Schedule = scheduleView, Visit = visit})
  </code></pre>
  
  <p>The problem is that I need to load also <code>Patient</code> property of <code>Visit</code> type. But when I write </p>
  
  <pre><code>query = (query as ObjectQuery&lt;ScheduleView&gt;).Include("Visit.Patient");
  </code></pre>
  
  <p>I receive a runtime error</p>
  
  <blockquote>
    <p>Unable to cast the type
    'System.Linq.IQueryable<code>1' to type
    'System.Data.Objects.ObjectQuery</code>1'.
    LINQ to Entities only supports casting
    Entity Data Model primitive types.</p>
  </blockquote>
  
  <p>So, the question is - how to force query to include something within my custom type?</p>