title: The entity type List requires a primary key to be defined
body: <p>I'm using .NET 5 and Entity Framework as ORM. I want to use a code-first database approach.</p>
  <p>I have 2 entity classes:</p>
  <pre><code>public class PurchaseOrderItem
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public double Price { get; set; }
  
      [ForeignKey(&quot;PurnchaseOrder&quot;)]
      public int PurnchaseOrderId { get; set; }
      public PurchaseOrder PurchaseOrder { get; set; }
  }
  
  public class PurchaseOrder
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public DateTime  CreationDate { get; set; }
      public List&lt;PurchaseOrderItem&gt; PurchaseOrderItems { get; set; }
  
      [NotMapped]
      public double TotalPrice
      {
          get
          {
              return PurchaseOrderItems.Sum(x =&gt; x.Price);
          }
      }
  }
  </code></pre>
  <p>But when I try to add new migration, I get the error like this:</p>
  <blockquote>
  <p>The entity type 'List' requires a primary key to be defined. If you intended to use a keyless entity type, call 'HasNoKey' in 'OnModelCreating'. For more information on keyless entity types, see <a href="https://go.microsoft.com/fwlink/?linkid=2141943" rel="nofollow noreferrer">https://go.microsoft.com/fwlink/?linkid=2141943</a>.</p>
  </blockquote>
  <p>Also my db context class:</p>
  <pre><code>public class ItemsAppDbContext : DbContext
  {
      public ItemsAppDbContext(DbContextOptions options) : base(options)
      {
      }
  
      public DbSet&lt;AppUser&gt; Users { get; set; }
      public DbSet&lt;PurchaseOrderItem&gt; PurchaseOrderItems { get; set; }
      public DbSet&lt;PurchaseOrder&gt; PurchaseOrders { get; set; }
  
      protected override void OnModelCreating(ModelBuilder modelBuilder)
      {
          modelBuilder.Entity&lt;PurchaseOrder&gt;()
                      .HasOne(p =&gt; p.PurchaseOrderItems)
                      .WithMany()
                      .OnDelete(DeleteBehavior.Cascade);
      }
  }
  </code></pre>