How to: Retrieve Entity Conflict Information (LINQ to SQL)
You can use objects of the ObjectChangeConflict class to provide information about conflicts revealed by ChangeConflictException exceptions. For more information, see Optimistic Concurrency Overview (LINQ to SQL).
Example
The following example iterates through a list of accumulated conflicts.
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
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();
}
}