2013-08-04 22 views
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整數。

回答

0

這是因爲我在更新數據庫時遇到了一些問題。需要手動刪除此表並重新創建它。現在工作正常。