Note that there are some explanatory texts on larger screens.

plurals
  1. PO"EntityType has no key defined" exception although key is defined with HasKey
    primarykey
    data
    text
    <p>Using EF 5 (reverse engineered code first), my model was working fine until it suddenly stopped.</p> <blockquote> <p>\tSystem.Data.Entity.Edm.EdmEntityType: : EntityType 'ProjectsDate' has no key defined. Define the key for this EntityType.</p> <p>\tSystem.Data.Entity.Edm.EdmEntityType: : EntityType 'ProjectsRisk' has no key defined. Define the key for this EntityType.</p> </blockquote> <p>I define a key using fluent API rather than attributes, here is my ProjectsDates classes.</p> <blockquote> <pre><code>public partial class ProjectsDate { public string OSProjectCode { get; set; } public Nullable&lt;System.DateTime&gt; TargetStart { get; set; } public Nullable&lt;System.DateTime&gt; EndDateOriginal { get; set; } public Nullable&lt;System.DateTime&gt; EndDateChangeControl { get; set; } public Nullable&lt;System.DateTime&gt; EndDateActual { get; set; } public Nullable&lt;System.DateTime&gt; GoLiveAgreed { get; set; } public Nullable&lt;System.DateTime&gt; GoLiveActual { get; set; } public virtual Project Project { get; set; } } </code></pre> </blockquote> <pre><code>public class ProjectsDateMap : EntityTypeConfiguration&lt;ProjectsDate&gt; { public ProjectsDateMap() { // Primary Key this.HasKey(t =&gt; t.OSProjectCode); // Properties this.Property(t =&gt; t.OSProjectCode) .IsRequired() .HasMaxLength(10); // Table &amp; Column Mappings this.ToTable("ProjectsDates"); this.Property(t =&gt; t.OSProjectCode).HasColumnName("OSProjectCode"); this.Property(t =&gt; t.TargetStart).HasColumnName("TargetStart"); this.Property(t =&gt; t.EndDateOriginal).HasColumnName("EndDateOriginal"); this.Property(t =&gt; t.EndDateChangeControl).HasColumnName("EndDateChangeControl"); this.Property(t =&gt; t.EndDateActual).HasColumnName("EndDateActual"); this.Property(t =&gt; t.GoLiveAgreed).HasColumnName("GoLiveAgreed"); this.Property(t =&gt; t.GoLiveActual).HasColumnName("GoLiveActual"); // Relationships this.HasRequired(t =&gt; t.Project) .WithOptional(t =&gt; t.ProjectsDate); } } </code></pre> <p>Why doesn't EF see my fluent API mapping?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload