How to fix System.Data.Edm.EdmEntityType has no key

前端 未结 6 1959
误落风尘
误落风尘 2021-01-08 01:17

Does anybody know how to fix this error:

System.Data.Edm.EdmEntityType: : EntityType \'BlogTags\' has no key defined. Define the key for this EntityTy

6条回答
  •  失恋的感觉
    2021-01-08 01:28

    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.

提交回复
热议问题