我想學習MVC3。我只是在嘗試將用戶添加到數據庫。實體框架添加用戶數據庫錯誤
db.U1_Users.Add(u1_Users);
db.SaveChanges();
當它進入保存時發生錯誤。 我這是添加功能的問題。
我得到的錯誤
InnerException = {"Cannot insert the value NULL into column 'U1_UserID', table
'Admin.dbo.U1_User'; column does not allow nulls. INSERT fails.\r\nThe statement has been terminated."}
編輯
U1_UserID是主鍵。
這是模型:
public class U1_User
{
public int U1_UserID { get; set; }
public string U1_UserName {get;set;}
}
這是因爲你的模型定義有一個問題,請您發佈模型類的源代碼。 – dknaack