방법: 멤버 충돌 정보 검색(LINQ to SQL)
MemberChangeConflict 클래스를 사용하여 충돌의 각 멤버에 대한 정보를 검색할 수 있습니다. 이와 동일한 컨텍스트에서 멤버의 충돌에 대한 사용자 지정 처리를 제공할 수 있습니다. 자세한 내용은 낙관적 동시성 개요(LINQ to SQL)를 참조하십시오.
예제
다음 코드에서는 ObjectChangeConflict 개체를 반복합니다. 그런 다음 각 개체에 대해 MemberChangeConflict 개체를 반복합니다.
참고 |
---|
Member 정보를 제공하려면 System.Reflection을 포함합니다. |
' Add 'Imports System.Reflection' for this section.
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 As Object = occ.Object
Console.WriteLine("Table name: " & metatable.TableName)
Console.Write("Customer ID: ")
Console.WriteLine(entityInConflict.CustomerID)
For Each mcc As MemberChangeConflict In occ.MemberConflicts
Dim currVal = mcc.CurrentValue
Dim origVal = mcc.OriginalValue
Dim databaseVal = mcc.DatabaseValue
Dim mi As MemberInfo = mcc.Member
Console.WriteLine("Member: " & mi.Name)
Console.WriteLine("current value: " & currVal)
Console.WriteLine("original value: " & origVal)
Console.WriteLine("database value: " & databaseVal)
Console.ReadLine()
Next
Next
End Try
// Add 'using System.Reflection' for this section.
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);
foreach (MemberChangeConflict mcc in occ.MemberConflicts)
{
object currVal = mcc.CurrentValue;
object origVal = mcc.OriginalValue;
object databaseVal = mcc.DatabaseValue;
MemberInfo mi = mcc.Member;
Console.WriteLine("Member: {0}", mi.Name);
Console.WriteLine("current value: {0}", currVal);
Console.WriteLine("original value: {0}", origVal);
Console.WriteLine("database value: {0}", databaseVal);
Console.ReadLine();
}
}
}