1
我的應用程序是MVC 5.2,首先使用EF 6.1數據庫。沒用過枚舉之前,我試圖從下拉列表存儲在以下鍵值:EnumDropDownListFor擴展現有的數據庫
public partial class Sleep {
public Nullable<int> SleepId {get;set;}
}
要採取新的@ HTML.EnumDropDownListFor的優勢,我增加了以下部分類
public enum SleepValues : int
{
Good = 1,
Bad = 2,
NotWell = 3
}
並改變了原有的類
public Nullable<SleepValues > SleepId {get;set;}
我得到以下錯誤:
The entity type Sleep is not part of the model for the current context.
希望你的建議。
你的睡眠表在你的分貝? – Jags 2014-11-02 02:25:21
是的。它有Id,SleepId和theDay。 – hncl 2014-11-02 02:28:13
您是否將實體添加到context.Add(實體)等上下文中?什麼是你的對象的EntityState? – Flaudre 2014-11-02 02:59:30