title: Entity Framework 6 and composite primary key, duplicate names
body: <p>I have a class that looks like this.</p>
  
  <pre><code>public class MyClass
  {
      public Object1 Object1 { get; set; }
      public Object2 Object2 { get; set; }
      public int Order { get; set; }
      public DateTime Created { get; set; }
  }
  </code></pre>
  
  <p>MyClass is a connection table with two additional columns.</p>
  
  <p>Entity Mapping:</p>
  
  <pre><code>public class MyClassMap : EntityTypeConfiguration&lt;MyClass&gt;
  {
      public MyClassMap()
      {
          ToTable("dbo.MyClass");
  
          HasKey(pc =&gt; new { pc.Object1.Id, pc.Object2.Id });
  
          Property(x =&gt; x.Order).IsOptional();
          Property(x =&gt; x.Created).HasColumnType("DateTime").IsRequired();
      }
  }
  </code></pre>
  
  <p>The problem occurs when I want create a composite primary key for MyClass. I want the primary key like this:</p>
  
  <pre><code>HasKey(pc =&gt; new { pc.Object1.Id, pc.Object2.Id });
  </code></pre>
  
  <p>The problem is that this is not allowed.
  An anonymous type cannot have multiple properties with the same name</p>
  
  <p>I could of course name my Id property on class Object1 to Object1Id and my Id property on class Object2 to Object2Id but I don't want that.</p>
  
  <p>I could also add another property on MyClass called Id and use this as primary key but want to avoid that too.</p>
  
  <p>Is there an alternative way to solve this problem?</p>