MemberChangeConflict 类

定义

表示以下情况:由于自客户端上次读取成员值后这些值已被更新,因此尝试的更新失败。

public ref class MemberChangeConflict sealed
public sealed class MemberChangeConflict
type MemberChangeConflict = class
Public NotInheritable Class MemberChangeConflict
继承
MemberChangeConflict

示例

// 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();
        }
    }
}
' 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

注解

以下示例演示如何检索有关冲突成员的信息。

属性

CurrentValue

获取发生冲突的成员的当前值。

DatabaseValue

获取发生冲突的成员的数据库值。

IsModified

获取一个值,该值指示自上次读取或刷新数据库后,是否已更改成员数据。

IsResolved

获取一个值,该值指示是否已解决冲突。

Member

获取有关发生冲突的成员的元数据信息。

OriginalValue

获取发生冲突的成员的原始值。

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
Resolve(Object)

指定要设置为发生冲突的成员的当前值的值。

Resolve(RefreshMode)

使用 RefreshMode 参数可自动指定要设置为发生冲突的成员的当前值的值。

ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于