I’m using EF reverse engineer code First in order to get my POCOs and mapping tables.
I get folowing exception : EntityType ‘MYPOCO’ has no key defined. Define the key for this EntityType.
I added [Key] attribute on pk field and it works fine. But :
How come [Key] attribute has to be set on the poco PK attribute
[Key] // what's the reason for this redundancy with HasKey() in mapping class ?
public int ID_MYPOCO { get; set; }
whereas it is allready mentioned in the mapping class …
public class MYPOCOMap : EntityTypeConfiguration<MYPOCO>
{
public MYPOCOMap()
{
// Primary Key
this.HasKey(t => t.ID_MYPOCO);
}
}
It is working and it is no big deal but wondering if there was any reason for this redundancy ?
Any how, very pleased with EF reverse engineering, my favorite way over the four ways to map DB.
The difference is the former is at
compiletime and the later is atrun time.