作法:指定用於測試並行衝突的成員How to: Specify Which Members are Tested for Concurrency Conflicts

將三個列舉的其中一個LINQ to SQLLINQ to SQL套用至屬性ColumnAttribute上的UpdateCheck屬性,以指定要在偵測開放式平行存取衝突的更新檢查中包含哪些成員。Apply one of three enums to the LINQ to SQLLINQ to SQL UpdateCheck property on a ColumnAttribute attribute to specify which members are to be included in update checks for the detection of optimistic concurrency conflicts.

UpdateCheck 屬性 (在設計階段對應) 是與 LINQ to SQLLINQ to SQL 中的執行階段並行存取功能搭配使用。The UpdateCheck property (mapped at design time) is used together with run-time concurrency features in LINQ to SQLLINQ to SQL. 如需詳細資訊, 請參閱開放式平行存取:總覽For more information, see Optimistic Concurrency: Overview.

注意

只要未將成員指定為 IsVersion=true,原始成員值就會與目前資料庫狀態進行比較。Original member values are compared with the current database state as long as no member is designated as IsVersion=true. 如需詳細資訊,請參閱 IsVersionFor more information, see IsVersion.

如需程式碼範例,請參閱 UpdateCheckFor code examples, see UpdateCheck.

若一律要使用這個成員來偵測衝突To always use this member for detecting conflicts

  1. UpdateCheck 屬性 (Property) 加入至 ColumnAttribute 屬性 (Attribute)。Add the UpdateCheck property to the ColumnAttribute attribute.

  2. UpdateCheck 屬性 (Property) 值設定為 AlwaysSet the UpdateCheck property value to Always.

若永不使用這個成員來偵測衝突To never use this member for detecting conflicts

  1. UpdateCheck 屬性 (Property) 加入至 ColumnAttribute 屬性 (Attribute)。Add the UpdateCheck property to the ColumnAttribute attribute.

  2. UpdateCheck 屬性 (Property) 值設定為 NeverSet the UpdateCheck property value to Never.

若只有在應用程式已變更成員的值時,才使用這個成員來偵測衝突To use this member for detecting conflicts only when the application has changed the value of the member

  1. UpdateCheck 屬性 (Property) 加入至 ColumnAttribute 屬性 (Attribute)。Add the UpdateCheck property to the ColumnAttribute attribute.

  2. UpdateCheck 屬性 (Property) 值設定為 WhenChangedSet the UpdateCheck property value to WhenChanged.

範例Example

下列範例指定 HomePage 物件永遠不應該在更新檢查期間進行測試。The following example specifies that HomePage objects should never be tested during update checks. 如需詳細資訊,請參閱 UpdateCheckFor more information, see UpdateCheck.

[Column(Storage="_HomePage", DbType="NText", UpdateCheck=UpdateCheck.Never)]
public string HomePage
{
    get
    {
        return this._HomePage;
    }
    set
    {
        if ((this._HomePage != value))
    {
        this.OnHomePageChanging(value);
        this.SendPropertyChanging();
            this._HomePage = value;
        this.SendPropertyChanged("HomePage");
            this.OnHomePageChanged();
    }
    }
}
<Column(Storage:="_HomePage", DbType:="NText", UpdateCheck:=UpdateCheck.Never)>  _
Public Property HomePage() As String
    Get
        Return Me._HomePage
    End Get
    Set(ByVal value As String)
        If ((Me._HomePage <> value)  _
            = false) Then
        Me.OnHomePageChanging(value)
            Me.SendPropertyChanging
            Me._HomePage = value
            Me.SendPropertyChanged("HomePage")
            Me.OnHomePageChanged
        End If
    End Set
End Property

另請參閱See also