Does anybody know how to fix this error:
System.Data.Edm.EdmEntityType: : EntityType 'BlogTags' has no key defined. Define the key for this EntityType.
Using MVC 3 with Entity Framework.
Just put [Key] on top of your property (which is presenting primary key). Something like this,
[Key]
public int BlogTypeId { get; set; }
MVC3 will automatically recognize an entity's Key if it follows the convention 'Id' or 'EntityNameId'. Additionally, the entity must expose this as a PROPERTY AND it must be PUBLIC. I made the mistake of using protected for my property and got this error.
A good example is:
public int Id { get; set; }
OR
public int EntityNameId { get; set; }
Use the [Key] attribute if you can't follow this convention OR if you want to be very explicit in your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With