Condividi tramite


DataContext.ChangeConflicts Property

Gets a collection of objects that represent discrepancies between the current client value and the current database value of a field in a list item.

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

Syntax

'Declaration
Public Property ChangeConflicts As ChangeConflictCollection
    Get
    Friend Set
'Usage
Dim instance As DataContext
Dim value As ChangeConflictCollection

value = instance.ChangeConflicts
public ChangeConflictCollection ChangeConflicts { get; internal set; }

Property Value

Type: Microsoft.SharePoint.Linq.ChangeConflictCollection
A ChangeConflictCollection each of whose members represents a discrepancy.

Remarks

At least one member of the property also represents a concurrency conflict that was detected when SubmitChanges() was last called. ChangeConflicts is not populated unless there was at least one concurrency conflict: a discrepancy between the current database value of the field and the value it had when it was last retrieved by the current process. If a conflict is found, SubmitChanges() also populates ChangeConflicts with objects that represent any discrepancy between the current client value and the current database value.

Typically, your code will catch a ChangeConflictException and resolve the discrepancies in ChangeConflicts in the catch (Catch in Visual Basic) block.

Examples

The following is an example of how the ChangeConflicts property is used in a catch block.

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

Microsoft.SharePoint.Linq Namespace