加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 无法使用mvc3定义模型的键

发布时间:2020-12-15 03:53:44 所属栏目:百科 来源:网络整理
导读:我正在尝试使用mvc3方法在数据库中设置字段.当我运行程序时,我得到了一个 System.Data.Edm.EdmEntityType: : EntityType ‘CarModel’ has no key defined. Define the key for this EntityType. 我的模型看起来像这样 public class CarModel{ public string
我正在尝试使用mvc3方法在数据库中设置字段.当我运行程序时,我得到了一个

System.Data.Edm.EdmEntityType: : EntityType ‘CarModel’ has no key defined. Define the key for this EntityType.

我的模型看起来像这样

public class CarModel
{

    public string VIN { get; set; }
    public string Make { get; set; }
    public string Model { get; set; }
    public string Year { get; set; }
    public string Color { get; set; }
    public string Mileage { get; set; }
    public string Description { get; set; }
}

我已经看到人们在哪里添加ID,但数据库没有ID属性.当我尝试在VIN上面添加[Key]时,它是数据库中的主键.它在键下产生红色波浪形错误.

似乎我错过了一些参考.

解决方法

您缺少的引用可能是System.ComponentModel.DataAnnotations;如果您键入Ctrl-,这不会为您添加.光标旁边的[Key]?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读