none
LINQ2SQL Conflicts are not resolved when submitting Changes RRS feed

  • Question

  • Hi there,

    i've got one question regarding linq2sql.

    I' am using this sample, when i am saving a contact and somebody made changes in the database i become a ChangeConflictException. Now the problem is that, when i resolve the conflict, and submit again, no changes are made to the database. I am using a timestamp column for the row versioning. Is there a posibility to resolve this issue?
            public static void SaveContact(temptable contact)
            {
                using (var dataContext = new DataClasses1DataContext())
                {
                    if (contact.ContactID == 0)
                    {
                        dataContext.temptables.InsertOnSubmit(contact);
                    }
    
                    else
                    {
                        dataContext.temptables.Attach(contact, true);
                    }
                    try
                    {
                        dataContext.SubmitChanges(ConflictMode.ContinueOnConflict);
    
                    }
                    catch (ChangeConflictException)
                    {
                        dataContext.Log = Console.Out;
                       dataContext.ChangeConflicts.ResolveAll(RefreshMode.KeepChanges);
                    }
                    dataContext.SubmitChanges(ConflictMode.ContinueOnConflict);
                }
            }
    Thursday, November 26, 2009 9:32 AM

Answers

  • RefreshMode.KeepChanges merges the changes and database values are overwritten only when the current changeset has also modified that value. Try changing it to RefreshMode.KeepCurrentValues.

    context.ChangeConflicts.ResolveAll(

    RefreshMode.KeepCurrentValues);


    Regards,

    kashif
    • Marked as answer by Yichun_Feng Thursday, December 3, 2009 2:24 AM
    Friday, November 27, 2009 11:44 AM