Anvisningar: Hämta information om entitetskonflikt
Du kan använda objekt i ObjectChangeConflict klassen för att ange information om konflikter som avslöjas av ChangeConflictException undantag. Mer information finns i Optimistisk samtidighet: Översikt.
Exempel
I följande exempel itereras genom en lista över ackumulerade konflikter.
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