【发布时间】:2011-01-12 13:04:05
【问题描述】:
数据库中的'Category'表定义如下:
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();
我得到错误:
无法插入显式值 表“类别”中的标识列 当 IDENTITY_INSERT 设置为 OFF 时。
但我没有插入 CategoryID!我希望它获得自动价值!
【问题讨论】:
-
谢谢,问题出在模型更新上!把它写成答案,我会接受的:)
-
好的,完成 - 让我的 cmets 成为答案 - 谢谢!
标签: c# entity-framework