实体框架插入不起作用.非典型错误

Evg*_*kim 1 .net firebird frameworks entity

我试图在Entity Framework中向我的实体插入行.它适用于第一次插入操作,但它不适用于第二次插入操作.我使用Framework 4,C#和FireBird数据库.这是我的代码部分

rec = new T_MEDIAPLAN_REC();
//
//... initialization for T_MEDIAPLAN_REC
//
BossTVEntities.AddToT_MEDIAPLAN_REC(rec);
BossTVEntities.SaveChanges();
Run Code Online (Sandbox Code Playgroud)

它在第二次SaveChanges()调用后给出了这个异常:

"The changes to the database were committed successfully, but an error occurred 
while updating the object context. The ObjectContext might be in an inconsistent 
state. Inner exception message: AcceptChanges cannot continue because the 
object's key values conflict with another object in the ObjectStateManager. 
Make sure that the key values are unique before calling AcceptChanges."
Run Code Online (Sandbox Code Playgroud)

我试着看看DataBase.目标实体中有两个插入的记录具有不同的Id.所以,我不知道这种行为的原因是什么.

我使用Visual Studio 2010 SP1 Professional,Firebird 2.5和.NET提供程序,C#,.NET Framework 4.0

它不适用于数据库中的每个实体.

das*_*ght 6

当在数据库中生成主键时,通常会发生此错误,但EF未正确配置,请在插入后从数据库中读取值.结果,两个插入的项目都在EF上下文中以空键结束,从而触发错误.

由于插入的数据在数据库中具有不同的键,因此您的数据库架构似乎是正确的.你需要检查你的EDM,看看StoreGeneratedPatternPK列上的设置是Identity什么,或者火鸟应该是什么.