Error: system.data.entity.edm.edm entitytype entity type has no key defined

Cause: 

No Primary Key is defined. Visual Studio generally looks out for an entityproperty int ID or similar and set it as a primary key. However, if our primary key is something like “Username” then we need to specify which one it is.

 

Solution:

Include the namespace:

using System.ComponentModel.DataAnnotations;

Before your Primary Key add the following attribute:

[Key]