title: IQueryable Entity Framework POCO Mappings
body: <p>I am using ASP.NET MVC2 with EF4. I need to create POCOs for two of my classes PersonP and AddressP, which correspond to their EF4 'complex' classes (which include things like navigation properties and OnPropertyChanged()). Mapping just PersonP by itself works fine, but PersonP contains AddressP (foreign key) - how do I map this using an IQueryable expression?</p>
  
  <p>Here is what I've tried:</p>
  
  <pre><code>class AddressP
  {
   int Id { get; set; }
   string Street { get; set; }
  }
  
  class PersonP
  {
   int Id { get; set; }
   string FirstName { get; set; }
   AddressP Address { get; set; }
  }
  
  IQueryable&lt;PersonP&gt; persons = _repo.QueryAll()
      .Include("Address")
      .Select(p =&gt; new PersonP
  {
   Id = p.Id,
   FirstName = p.FirstName,
   //Address = p.Address &lt;-- I'd like to do this, but p.Address is Address, not AddressP
   //Address = (p.Address == null) ? null :
   //new AddressP    &lt;-- does not work; can't use CLR object in LINQ runtime expression
   //{
   // Id = p.Address.Id,
   // Street = p.Address.Street
   //}
  });
  </code></pre>
  
  <ol>
  <li><p>Without the <code>.Include("Address")</code> I would not retrieve anything from the Address table is this correct?</p></li>
  <li><p>How do I map <code>Address</code> to <code>AddressP</code> inside <code>PersonP</code>, using the <code>Select()</code> statement above?</p></li>
  </ol>
  
  <p>Thank you.</p>