Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello ,
I am working on telerik winformc#,

I have one button its text is Delete and it will change on the event of one of my radiobutton to Re-Open.


on the click of that button function of that as below.

C#
private void Delete()
      {
          if (File != null)
          {
              if (CloseOpenText == "Delete")
              {
                  //if (MessageBoxResult.Yes == MessageBox.Show("Do you want to Delete selected File?", "Delete", MessageBoxButton.YesNo, MessageBoxImage.Warning))
                  if (DialogResult.Yes == RadMessageBox.Show("Do you want to Delete selected File?", "Delete", MessageBoxButtons.YesNo, RadMessageIcon.Question))
                  {
                      this.File = _fileModel.Delete(_file);
                      BindData();
                      //   MessageBox.Show("Data has been deleted successfully", "Data Saved!", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information);
                      RadMessageBox.Show("Data has been deleted successfully", "Data Saved!", MessageBoxButtons.OK, RadMessageIcon.Info);
                  }

              }
              else
              {
                  //if (MessageBoxResult.Yes == MessageBox.Show("Do you want to Re-Open selected File?", "Re-Open File", MessageBoxButton.YesNo, MessageBoxImage.Warning))
                  if (DialogResult.Yes == RadMessageBox.Show("Do you want to Re-Open selected File?", "Re-Open File", MessageBoxButtons.YesNo, RadMessageIcon.Question))
                  {
                      this.File = _fileModel.ReOpen(_file);
                      //MessageBox.Show("File has been restore successfully", "File Re-Opened!", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information);
                      RadMessageBox.Show("File has been restore successfully", "File Re-Opened!", MessageBoxButtons.OK, RadMessageIcon.Info);
                  }
              }
          }
      }

for the Re-Open functionality i have problem.

function of that as below.


SQL
public File ReOpen(File file)
        {
            file.ClosedFileNumber = string.Empty;
            file.FileStatus = true;

            //_repository.ApplyChanges(file);
            Update(file);


            // RaiseEvent(file, ChangeAction.Add);
            //Audit trail
            //TODO: MyAuditTrialModel.Add<File>(Helper.Actions.CU_File, Helper.TableNames.File, file);

            return file;

        }



for the update function is as below.

C#
private File Update(File item)
        {
            _context.Files.ApplyChanges(item);
            _context.ObjectStateManager.ChangeObjectState(item, System.Data.EntityState.Modified);
            _context.SaveChanges(true);
            return item;
        }



I have find the error of

"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".

error throws at
C#
case (ObjectState.Unchanged):
                   context.ObjectStateManager.ChangeObjectState(entity, EntityState.Unchanged);
                   break;



help me for that
Posted
Updated 12-Feb-15 19:55pm
v2
Comments
Sergey Alexandrovich Kryukov 13-Feb-15 1:40am    
Your keys are not unique. You did not show a single line with the keys, so please find it yourself. Use the debugger. You did not "find the error". This is exception; and you did not even bother to find out the line where it was thrown.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900