共用方式為


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 要使用的值。

適用於