title: EntityType 'x' has no key defined, Reuse DB First in Code First
body: <p>I have a class named 'Authority' in a library that created by Database First method</p>
  
  <p>As we know Database First generate all the classes automatically also Primary Key defined for each class,
  I also created 'User' class has a property of Authority class, in another library I have 'PacsUser' class derived from 'User' I am using code first approach to develop 'PacsUser'
  when I want PacsUser to return a specific user it gives me "EntityType 'Authority' has no key defined"</p>
  
  <p>I have to define key for Authority class in OnModelCreating of PacsUserDBContext like:</p>
  
  <pre><code>modelBuilder.Entity&lt;Authority&gt;().HasKey(e =&gt; e.AID);
  </code></pre>
  
  <p>why DbModelBuilder in PacsUserDBContext recognize Authority's primary key automatically? or at least by</p>
  
  <pre><code>modelBuilder.Entity&lt;Authority&gt;().ToTable("Authority");
  </code></pre>
  
  <p>all things work properly (just for example).</p>
  
  <p>They both(Authority bay DB-First and PacsUser by Code-First) are using Entity Framework ORM so</p>
  
  <p>Why Code first doesn't know Authority primary key ?</p>
  
  <p>Is there a way DbModelBuilder recognize primary keys automatically ?</p>
  
  <p>Any Idea would be appreciated.</p>