locked
Entity Conflict detected RRS feed

  • Question

  • Hi,

    I'll try to insert a record in a table one time if it not exists using RIA Services. I simplified my code to explain what I want to do.

    The problem is that if I update 2 risks in a same SubmitChanges, the UpdateRisk function is called twice as well but the second time, the entity created on the first call is not detected.

    So I get an error about conflict entity detected. I tried to add  this.ObjectContext.DetectChanges() but it doesn't work.

    How can I do that ?

    Thanks in advance,

    Ety.


            public void UpdateRisk(Risk currentRisk)
            {  // Searching if the entity already exists
                UserOwner userOwner = (from ow in this.ObjectContext.UserOwner where ow.IdOwner == 1 && ow.UserId == 1 select ow).FirstOrDefault();
                if (userOwner ==null)
                {  // Create new entity but not more than one time
                     userOwner = new userOwner {IdOwner =1, UserId=1};
                     InsertUserOwner(userOwner);
                }


                this.ObjectContext.Risk.AttachAsModified(currentRisk, this.ChangeSet.GetOriginal(currentRisk));
            }

    Thursday, March 29, 2012 12:10 PM

Answers