ObjectChangeConflict.Resolve 方法

定义

解决成员冲突。

重载

Resolve()

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

Resolve(RefreshMode)

使用指定的 RefreshMode 来解决成员冲突。

Resolve(RefreshMode, Boolean)

解决保留当前值且表示基线原始值的成员冲突。

Resolve()

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

public:
 void Resolve();
public void Resolve ();
member this.Resolve : unit -> unit
Public Sub Resolve ()

适用于

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(RefreshMode, Boolean)

解决保留当前值且表示基线原始值的成员冲突。

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

参数

refreshMode
RefreshMode

RefreshMode 的相应选择。

autoResolveDeletes
Boolean

如果为 true,则自动解决由数据库中不再存在的已修改对象产生的冲突。

适用于