如何修复多个添加的实体在EF中可能具有相同的主键?

时间:2015-08-18 11:15:21

标签: c# .net entity-framework c#-4.0

我使用的数据库表结构如下

RejectID int Primary Key
RecordingID nvarchar(500)
RejectedBy int

在一个按钮上单击我试图添加这样的对象:

 public void btnReject_click()
  {
          RejectedRecording currentRR = new RejectedRecording();

            currentRR.RecordingID = "hbi123kjubj27676";
            currentRR.RejectedBy = 5;

            objOmniPCXRecordEntities.RejectedRecordings.AddObject(currentRR);
   }

在其他按钮上单击我调用保存更改,如:

public void btnSave_click()
  {
        objOmniPCXRecordEntities.SaveChanges();
   }

如果我只尝试添加一个对象,但是在发生第二个记录异常的情况下

,它可以正常工作

Unable to determine the principal end of the 'OmniPCXRecordModel.FK_RejectedRecordings_RejectedRecordings' relationship. Multiple added entities may have the same primary key.

0 个答案:

没有答案