你的位置:首页 > ASP.net教程

[ASP.net教程]MVC初学


问题:

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();        }      }    }