【发布时间】:2015-08-17 21:47:45
【问题描述】:
所以基本上,我正在尝试使用 LINQ to Entity 向我的表中插入一条记录。
using (MyEntities container = new MyEntities())
{
container.MyTable.AddObject(record);
container.SaveChanges();
}
现在我的问题是:我要插入的表有一个列 ID,它是 PK 并且是一个身份字段。在我的模型中,我确保将列的StoreGeneratedPattern 属性设置为IDENTITY。但是,当我运行我的代码时,它仍然给我错误消息:
"Cannot insert explicit value for identity column in table 'MyTable' when IDENTITY_INSERT is set to OFF."
我是否缺少需要更新的模型的任何其他属性?
谢谢!
【问题讨论】:
-
显示你的映射代码
-
这是 EF 代码优先吗? stackoverflow.com/questions/12811931/…
标签: linq entity-framework linq-to-entities identity