MemberChangeConflict.Resolve 方法

定义

通过保留当前值并重置基线原始值以匹配较新数据库值来解决成员冲突。

重载

Resolve(RefreshMode)

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

Resolve(Object)

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

Resolve(RefreshMode)

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

public:
 void Resolve(System::Data::Linq::RefreshMode refreshMode);
public void Resolve (System.Data.Linq.RefreshMode refreshMode);
member this.Resolve : System.Data.Linq.RefreshMode -> unit
Public Sub Resolve (refreshMode As RefreshMode)

参数

refreshMode
RefreshMode

请参阅 RefreshMode

示例

以下示例使用数据库中的值覆盖当前值。

Northwnd db = new Northwnd("...");
try
{
    db.SubmitChanges(ConflictMode.ContinueOnConflict);
}

catch (ChangeConflictException e)
{
    Console.WriteLine(e.Message);
    foreach (ObjectChangeConflict occ in db.ChangeConflicts)
    {
        // All database values overwrite current values.
        occ.Resolve(RefreshMode.OverwriteCurrentValues);
    }
}
Dim db As New Northwnd("...")

Try
    db.SubmitChanges(ConflictMode.ContinueOnConflict)

Catch ex As ChangeConflictException
    Console.WriteLine(ex.Message)

    For Each occ As ObjectChangeConflict In db.ChangeConflicts
        ' All database values overwrite current values.
        occ.Resolve(Data.Linq.RefreshMode.OverwriteCurrentValues)
    Next

End Try

以下示例演示如何将原始值与从数据库检索到的值交换。 不会修改当前值。

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

catch (ChangeConflictException e)
{
    Console.WriteLine(e.Message);
    foreach (ObjectChangeConflict occ in db.ChangeConflicts)
    {
        //No database values are merged into current.
        occ.Resolve(RefreshMode.KeepCurrentValues);
    }
}
Try
    db.SubmitChanges(ConflictMode.ContinueOnConflict)

Catch ex As ChangeConflictException
    Console.WriteLine(ex.Message)

    For Each occ As ObjectChangeConflict In db.ChangeConflicts
        ' No database values are merged into current.
        occ.Resolve(Data.Linq.RefreshMode.KeepCurrentValues)
    Next

End Try

以下示例保留已更改的当前值,但使用数据库值更新其他值。

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

catch (ChangeConflictException e)
{
    Console.WriteLine(e.Message);
    // Automerge database values for members that client
    // has not modified.
    foreach (ObjectChangeConflict occ in db.ChangeConflicts)
    {
        occ.Resolve(RefreshMode.KeepChanges);
    }
}

// Submit succeeds on second try.
db.SubmitChanges(ConflictMode.FailOnFirstConflict);
Try
    db.SubmitChanges(ConflictMode.ContinueOnConflict)

Catch ex As ChangeConflictException
    Console.WriteLine(ex.Message)

    For Each occ As ObjectChangeConflict In db.ChangeConflicts
        ' Automerge database values into current for members
        ' that client has not modified.
        occ.Resolve(Data.Linq.RefreshMode.KeepChanges)
    Next

End Try

' Submit succeeds on second try.
db.SubmitChanges(ConflictMode.FailOnFirstConflict)

注解

以下示例显示使用 的各种值生成 RefreshMode的结果。

适用于

Resolve(Object)

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

public:
 void Resolve(System::Object ^ value);
public void Resolve (object value);
member this.Resolve : obj -> unit
Public Sub Resolve (value As Object)

参数

value
Object

要设置为当前值的值。

注解

此处设置的值是要在后续 SubmitChanges 操作中使用的值。

适用于