Procedura: recuperare informazioni sui conflitti di entitàHow to: Retrieve Entity Conflict Information

È possibile usare oggetti della classe ObjectChangeConflict per fornire informazioni sui conflitti rivelati dalle eccezioni ChangeConflictException.You can use objects of the ObjectChangeConflict class to provide information about conflicts revealed by ChangeConflictException exceptions. Per ulteriori informazioni, vedere la concorrenza ottimistica: Panoramica.For more information, see Optimistic Concurrency: Overview.

EsempioExample

L'esempio riportato di seguito consente di scorrere un elenco di conflitti accumulati.The following example iterates through a list of accumulated conflicts.

Northwnd db = new Northwnd("...");

try
{
    db.SubmitChanges(ConflictMode.ContinueOnConflict);
}

catch (ChangeConflictException e)
{
    Console.WriteLine("Optimistic concurrency error.");
    Console.WriteLine(e.Message);
    foreach (ObjectChangeConflict occ in db.ChangeConflicts)
    {
        MetaTable metatable = db.Mapping.GetTable(occ.Object.GetType());
        Customer entityInConflict = (Customer)occ.Object;
        Console.WriteLine("Table name: {0}", metatable.TableName);
        Console.Write("Customer ID: ");
        Console.WriteLine(entityInConflict.CustomerID);
        Console.ReadLine();
    }
}
Dim db As New Northwnd("...")

Try
    db.SubmitChanges(ConflictMode.ContinueOnConflict)

Catch ex As ChangeConflictException
    Console.WriteLine("Optimistic concurrency error.")
    Console.WriteLine(ex.Message)
    For Each occ As ObjectChangeConflict In db.ChangeConflicts
        Dim metatable As MetaTable = db.Mapping.GetTable(occ.Object.GetType())
        Dim entityInConflict = occ.Object

        Console.WriteLine("Table name: " & metatable.TableName)
        Console.Write("Customer ID: ")
        Console.WriteLine(entityInConflict.CustomerID)
        Console.ReadLine()
    Next
End Try

Vedere ancheSee Also

Procedura: gestire i conflitti di modificheHow to: Manage Change Conflicts