微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我正在尝试使用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]?

原文地址:https://www.jb51.cc/csharp/93473.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐