EntityType 'ApplicantPosition' has no key defined

后端 未结 4 766
隐瞒了意图╮
隐瞒了意图╮ 2021-01-13 05:36

When running my first asp.net mvc application I got this error I thought that entity framework automatically would create the keys of column names that end with Id? isnt it

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-13 06:11

    EF Code First can only infer that a property is a primary key if the property is called Id or Id (or if it is annotated with the Key attribute). So you need to extend your e.g. ApplicantImage with an ApplicantImageId or Id property etc.

    Edit: An artice about the coneventions: Conventions for Code First

提交回复
热议问题