title: code first get values from foreign key constraint
body: <p>I've started a sample project with code first and get NULL value from entity which has a foreign key constraint.</p>
  
  <p>my model:</p>
  
  <pre><code>public class CustomerItem
  {
       [Key]
       public int Id { get; set; }
       public int Name{get;set;}
       public virtual IEnumerable&lt;OrderItem&gt; Order { get; set; }
  }
  
  public class OrderItem
  {
      [Key]
      public int Id { get; set; }
  
      [ForeignKey("CustomerItem")]
      public int CustomerId { get; set; }
      public virtual CustomerItem CustomerItem { get; set; }
  }
  </code></pre>
  
  <p>dataaccess linq query to get values:</p>
  
  <pre><code>public IEnumerable&lt;CustomerItem&gt; GetOrdersFromCustomerItem(int id)
  {
      return (from c in this.dax.Customer
             where c.Id.CompareTo(id) == 0
             select c).AsEnumerable().ToList();
  }
  </code></pre>
  
  <p>this query return NULL orders so I think there's some mistake in this query.
  How can I wire up this entity with foreign key table?</p>
  
  <p>Thanks  </p>
  
  <p><strong>Updated</strong> my query to get all customers (and their orders) to this:</p>
  
  <pre><code>public IEnumerable&lt;CustomerItem&gt; GetAllCustomers()
  {
      return (from c in this.dax.Customer
              select new 
              {
                  //Properties
                  OrderItem = c.OrderItem
              }).AsEnumerable.ToList().select(s =&gt; new CustomerItem
              {
                 //Properties
                 OrderItem = s.OrderItem, //here I got the exception I wrote in comment
              }).ToList();
  }
  </code></pre>