DuplicateKeyException trying to Remove and Add

6 posts, 0 answers
  1. Gene Allen
    Gene Allen avatar
    4 posts
    Member since:
    Apr 2010

    Posted 06 Apr 2010 Link to this post

    Hello, I'm new to Telerik and I'm trying having trouble getting a remove and readd to work.

    Here is my test code snippet:

          InspectionReport testNewIR = CopyIR(iScope, ir);  
          string IR_ID = irID.ToString();  
          InspectionReport air = InspectionReport.LoadIR(IR_ID, iScope);  
     
          iScope.Transaction.Begin();  
          iScope.Remove(air);  
          iScope.Transaction.Commit();  
     
          iScope.Transaction.Begin();  
          iScope.Add(testNewIR);  
          iScope.Transaction.Commit();  
     

    Here is the exception that I'm getting:
     "Instance of 'ppiatm.QAReporter.Data.ActionItem' with identity '714015106-3c49cf84-361b-4805-a8aa-946f0fc04c0d' already exists in the cache of the object scope."

    The ActionItem was actually removed from the database, but for some reason it's still in the IScope cache.

    What I'm trying to do is update the local database with an updated object from a central server.

    Can anyone point me to what I'm doing wrong?

    thanks,

    Gene

  2. Gene Allen
    Gene Allen avatar
    4 posts
    Member since:
    Apr 2010

    Posted 07 Apr 2010 Link to this post

    I couldn't get the dispose to empty the cache either.

    This throws the same exception

          InspectionReport testNewIR = MakeNewIR(iScope, ir);  
          string IR_ID = irID.ToString();  
          InspectionReport air = InspectionReport.LoadIR(IR_ID, iScope);  
     
          iScope.Transaction.Begin();  
          iScope.Remove(air);  
          iScope.Transaction.Commit();  
          iScope.Dispose();  
     
          IObjectScope kScope = ObjectScopeProvider2.GetNewObjectScope();  
          kScope.Transaction.Begin();  
          kScope.Add(testNewIR);  
          kScope.Transaction.Commit();  
     

    Any help would be great!

    Thanks
  3. DevCraft banner
  4. Gene Allen
    Gene Allen avatar
    4 posts
    Member since:
    Apr 2010

    Posted 08 Apr 2010 Link to this post

    I was able to figure out my problem.  Please consider the matter closed. :)
  5. Aaron Drenberg
    Aaron Drenberg avatar
    7 posts
    Member since:
    Jan 2010

    Posted 05 May 2010 Link to this post


    Hi Gene,

    I am having the same problem, and it occurs even when I try to execute a transaction against a new object scope. Would you be able to post your solution?

    Thanks.
  6. Gene Allen
    Gene Allen avatar
    4 posts
    Member since:
    Apr 2010

    Posted 05 May 2010 Link to this post

    For me , the problem was a reference was missing. 
    A child object wasn't pointing to it's parent, as soon as I fixed all the various object reference links, the error went away.

    Hope it helps,

    Gene
  7. Aaron Drenberg
    Aaron Drenberg avatar
    7 posts
    Member since:
    Jan 2010

    Posted 05 May 2010 Link to this post


    Gene,

    Thanks for your reply; that does help me understand a little more about when/why this might occur.

    I found the source of my own error last night. One of the objects on my graph had been retrieved from the View State. Unfortunately, the persistent entities cannot be serialized directly and then reattached. The recommended solution in my case is to use the Object Container.

    Aaron
Back to Top
DevCraft banner