在數據庫中的 '類別' 表中這樣定義:實體框架IDENTITY_INSERT
CategoryID - PK ,identity specification ON (only this column has identity)
Description
Title
我要插入新的數據:
Category cat = new Category
{
Description = "xxx",
Title = "yyy",
};
if (cat.EntityState == EntityState.Detached)
{
Articlerctx.AddToCategories(cat);
}
return Articlerctx.SaveChanges();
我得到錯誤:
Cannot insert explicit value for identity column in table 'Categories' when IDENTITY_INSERT is set to OFF.
但我不插入CategoryID!我希望它獲得自動價值!
謝謝,問題出現在模型更新中!寫它作爲答案,我會接受它:) – asker 2011-01-12 16:20:30
好,完成 - 使我的意見成爲一個答案 - 謝謝! – 2011-01-12 21:30:49