首页 > 技术文章 > MVC初学 - Entitytype has no key defined

zero530 2015-08-05 09:34 原文

问题:

entitytype has no key defined

 

Solution:

  1. 增加引用
  2. 增加关键字[Key]
  using System.ComponentModel.DataAnnotations;

[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_ContactsID", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]
        [Key]
        public int ContactsID
        {
            get
            {
                return this._ContactsID;
            }
            set
            {
                if ((this._ContactsID != value))
                {
                    this.OnContactsIDChanging(value);
                    this.SendPropertyChanging();
                    this._ContactsID = value;
                    this.SendPropertyChanged("ContactsID");
                    this.OnContactsIDChanged();
                }
            }
        }

 

推荐阅读