DataContext.SubmitChanges Method (ConflictMode)

Persists to the content database changes made by the current user to one or more lists using the specified failure mode; or, if a concurrency conflict is found, populates the ChangeConflicts property.

Namespace:  Microsoft.SharePoint.Linq
Assembly:  Microsoft.SharePoint.Linq (in Microsoft.SharePoint.Linq.dll)

Syntax

'Declaration
Public Sub SubmitChanges ( _
    failureMode As ConflictMode _
)
'Usage
Dim instance As DataContext
Dim failureMode As ConflictMode

instance.SubmitChanges(failureMode)
public void SubmitChanges(
    ConflictMode failureMode
)

Parameters

Exceptions

Exception Condition
InvalidOperationException

ObjectTrackingEnabled is false

- or -

At least one conflict in ChangeConflicts from the last time SubmitChanges() was called is not yet resolved.

ChangeConflictException

There is a concurrency conflict.

Remarks

The version of changed list items will be incremented. To persist changes without incrementing versions, use SubmitChanges(ConflictMode, Boolean).

Examples

The following example shows this overload of SubmitChanges() being used:

foreach (TeamMember teamMember in teamSite.TeamMembers)
{
    teamMember.TopTask = “Fiscal Planning”;
}

try 
{
    teamSite.SubmitChanges(ConflictMode.ContinueOnConflict);
}
catch (ChangeConflictException e) 
{
    foreach (ObjectChangeConflict changedListItem in teamSite.ChangeConflicts)
    {
        // If another user has changed properties of a non-manager,
        // leave that other user’s changes, except for the TopTask field.
        if (((TeamMember)changedListItem.Object).IsManager = false)
        {        
             foreach (MemberChangeConflict changedField in changedListItem.MemberConflicts)
            {
                if (changedField.Member.Name == “TopTask”)
                {
                    changedField.Resolve(RefreshMode.KeepCurrentValues);
                }
                else
                {
                    changedField.Resolve(RefreshMode.OverwriteCurrentValues);
                }
            }
        }
        // But if another user has changed properties of a manager, let this
        // process’s changes override the other user’s changes.
        else
        {
            changedListItem.Resolve(RefreshMode.KeepCurrentValues);
        }    
    }

    teamSite.SubmitChanges();
} // end catch
For Each teamMember As TeamMember In teamSite.TeamMembers
    teamMember.TopTask = "Fiscal Planning"
Next teamMember

Try
    teamSite. SubmitChanges(ConflictMode.ContinueOnConflict)
Catch e As ChangeConflictException
    For Each changedListItem As ObjectChangeConflict In teamSite.ChangeConflicts
        ' If another user has changed properties of a non-manager,
        ' leave that other user’s changes, except for the TopTask field.
        If Not (CType(changedListItem.Object, TeamMember)).IsManager Then
             For Each changedField As MemberChangeConflict In changedListItem.MemberConflicts
                If changedField.Member.Name = "TopTask" Then
                    changedField.Resolve(RefreshMode.KeepCurrentValues)
                Else
                    changedField.Resolve(RefreshMode.OverwriteCurrentValues)
                End If
             Next changedField
        ' But if another user has changed properties of a manager, let this
        ' process’s changes override the other user’s changes.
        Else
            changedListItem.Resolve(RefreshMode.KeepCurrentValues)
        End If
    Next changedListItem

    teamSite.SubmitChanges()
End Try ' end catch

See Also

Reference

DataContext Class

DataContext Members

SubmitChanges Overload

Microsoft.SharePoint.Linq Namespace