RefreshMode RefreshMode RefreshMode RefreshMode Enum

定义

定义 Refresh 方法如何处理开放式并发冲突。Defines how the Refresh method handles optimistic concurrency conflicts.

public enum class RefreshMode
public enum RefreshMode
type RefreshMode = 
Public Enum RefreshMode
继承

字段

KeepChanges KeepChanges KeepChanges KeepChanges 1

强制 Refresh 方法保留已更改的当前值,但将其他值更新为数据库值。Forces the Refresh method to keep the current value that has been changed, but updates the other values with the database values.

KeepCurrentValues KeepCurrentValues KeepCurrentValues KeepCurrentValues 0

强制 Refresh 方法使用从数据库检索的值替换原始值。Forces the Refresh method to swap the original value with the values retrieved from the database. 不会修改当前值。No current value is modified.

OverwriteCurrentValues OverwriteCurrentValues OverwriteCurrentValues OverwriteCurrentValues 2

强制 Refresh 方法使用数据库中的值重写所有当前值。Forces the Refresh method to override all the current values with the values from the database.

示例

下面的示例数据库中的值将覆盖当前值。The following example overwrites current values with values from the database.

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

下面的示例演示如何替换从数据库中检索的值的原始值。The following example shows how to swap the original value with the values retrieved from the database. 不会修改当前值。No current value is modified.

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

下面的示例保留已更改,但更新的其他值与数据库值的当前值。The following example keeps the current values that have been changed, but updates the other values with database values.

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)

注解

此枚举应用于所有Refresh重载。This enumeration applies to all Refresh overloads.

适用于