0
我正在使用MVC來生成我的數據庫。我有以下的代碼結構,我的用戶配置類:標識列插入空MVC代碼優先
[KeyAttribute()]
[DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string UserName { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string EmailAddress { get; set; }
這將生成數據庫很好,但是當我嘗試插入一條記錄,它說用戶ID不能爲空。我不明白爲什麼它不是自動生成一個Id整數。