title: Entity type ‘Business_attrib2object’ has composite primary key defined with data annotations. To set composite primary key, use fluent API
body: <p>I set composite primary key using fluent API, it is still an error, when I'm trying to create ClassesController (MVC Controller with Views Using Entity Framework).</p>
  
  <p>Declaring Classes class:</p>
  
  <pre><code>public partial class Classes
  {
      [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
      public Classes()
      {
          this.Business_attrib2object = new HashSet&lt;Business_attrib2object&gt;();
          this.Objects = new HashSet&lt;Objects&gt;();
      }
      [Key]
      public System.Guid IdClass { get; set; }
      public string Name { get; set; }
  
      [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
      public virtual ICollection&lt;Business_attrib2object&gt; Business_attrib2object { get; set; }
      [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
      public virtual ICollection&lt;Objects&gt; Objects { get; set; }
  }
  </code></pre>
  
  <p>Declaring Business_attrib2object class:</p>
  
  <pre><code> public partial class Business_attrib2object
  {
      [Key]
      public System.Guid IdClass { get; set; }
      [Key]
      public System.Guid IdAttribute { get; set; }
  
      public Nullable&lt;System.Guid&gt; IdAuthor { get; set; }
  
      public virtual Attributes Attributes { get; set; }
      public virtual Classes Classes { get; set; }
  }
  </code></pre>
  
  <p>DBContext:</p>
  
  <pre><code>public class Business_attrib2objectContext : DbContext
  {
      public DbSet&lt;Business_attrib2object&gt; Business_attrib2object { get; set; }
  
      protected override void OnModelCreating(ModelBuilder modelBuilder)
      {
          modelBuilder.Entity&lt;Business_attrib2object&gt;().HasKey(ba =&gt; new { ba.IdClass, ba.IdAttribute });      
      }
  
      public Business_attrib2objectContext(DbContextOptions&lt;Business_attrib2objectContext&gt; options)
          : base(options)
      {
          Database.EnsureCreated();
      }
  }
  </code></pre>
  
  <p>Creating controller:
  <a href="https://i.stack.imgur.com/aC2Ux.png" rel="noreferrer">Creating controller</a>
  Error:
  <a href="https://i.stack.imgur.com/7V2Ob.png" rel="noreferrer">Error message</a></p>