title: Entity Framework Core "The entity type 'XXX' requires a primary key to be defined."
body: <p>So I'm currently trying to create a code first migration with Entity Framework Core for a table that displays which lectures the application user has completed. My model looks like this:</p>
  
  <pre><code>public class LectureCompletion
  {
      [Key,  Column(Order = 0)]
      [ForeignKey("Lecture")]
      public Lecture LectureId { get; set; }
  
      [Key,  Column(Order = 1)]
      [ForeignKey("User")]
      public ApplicationUser UserId{ get; set; }
  
      public bool Completed { get; set; }
  }
  </code></pre>
  
  <p>I want to use the <code>UserId</code> and the <code>LectureId</code> as the unique composite key. However I get this error:</p>
  
  <blockquote>
    <p>The entity type 'LectureCompletion' requires a primary key to be defined.</p>
  </blockquote>
  
  <p>I don't understand why this is happening as I clearly have my key attributes in the correct positions? Am I able to use <code>ApplicationUser</code> as foreign/primary key?</p>
  
  <p>Here is my <code>Lecture</code> model:</p>
  
  <pre><code>public class Lecture
  {
      [Key]
      public int LectureId { get; set; }
  
      public string ModuleName { get; set; }
      public string LectureName { get; set; }
  }
  </code></pre>
  
  <p>And my <code>ApplicationDBContext.cs</code>:</p>
  
  <pre><code>public class ApplicationDbContext : IdentityDbContext&lt;ApplicationUser&gt;
  {
      public DbSet&lt;Lecture&gt; Lectures { get; set; }
      public DbSet&lt;LectureCompletion&gt; LectureCompletion { get; set; }
  
      public ApplicationDbContext(DbContextOptions&lt;ApplicationDbContext&gt; options)
          : base(options)
      {
      }
  
      protected override void OnModelCreating(ModelBuilder builder)
      {
          base.OnModelCreating(builder);
          // Customize the ASP.NET Identity model and override the defaults if needed.
          // For example, you can rename the ASP.NET Identity table names and more.
          // Add your customizations after calling base.OnModelCreating(builder);
      }
  }
  </code></pre>