title: Access parent entity from child in Entity Framework
body: <p>I have a parent entity <code>Device</code> which contains a list of <code>DeviceErrorLog</code> setup like so</p>
  
  <pre><code>public class Device
  {
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.None)]
      public long DeviceSerial { get; set; }
  
      public virtual ICollection&lt;DeviceLogEntry&gt; Errors { get; set; }
  }
  </code></pre>
  
  <p>This works fine but I want to be able to access <code>Device</code> from within <code>DeviceLogEntry</code> so I added the following:</p>
  
  <pre><code>public class DeviceLogEntry
  {        
      [Key]
      public int Id { get; set; }
  
      public virtual Device Device { get; set; }
  }
  </code></pre>
  
  <p>Now my database structure for the <code>DeviceLogEntry</code> table has 3 columns associated with the <code>Device</code>: <code>[Device_DeviceSerial],[Device_DeviceSerial1],[Device_DeviceSerial2]</code></p>
  
  <p>Have I missed a link or bit of code that prevents this?</p>
  
  <p><strong>Update</strong></p>
  
  <p>I have updated the code to include the device as a foreign key which has removed one extra column but I still seem to have one too many <code>[Device_DeviceSerial],[Device_DeviceSerial1]</code></p>
  
  <pre><code>public class DeviceLogEntry
  {        
      [Key, Column(Order = 0)]
      public int Id { get; set; }
  
      [Key, Column(Order = 1)]
      [ForeignKey("Device")]
      public long DeviceSerial { get; set; }
  }
  </code></pre>