AssociationAttribute 類別

定義

指定屬性表示資料庫關聯,例如外部索引鍵關聯性。

public ref class AssociationAttribute sealed : System::Data::Linq::Mapping::DataAttribute
[System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false)]
public sealed class AssociationAttribute : System.Data.Linq.Mapping.DataAttribute
[<System.AttributeUsage(System.AttributeTargets.Field | System.AttributeTargets.Property, AllowMultiple=false)>]
type AssociationAttribute = class
    inherit DataAttribute
Public NotInheritable Class AssociationAttribute
Inherits DataAttribute
繼承
AssociationAttribute
屬性

範例

private EntityRef<Customer> _Customer;
// ...
[Association(Name="FK_Orders_Customers", Storage="_Customer", ThisKey="CustomerID", IsForeignKey=true)]
public Customer Customer
{
    get
    {
        return this._Customer.Entity;
    }
    set
    {
        Customer previousValue = this._Customer.Entity;
        if (((previousValue != value)
                    || (this._Customer.HasLoadedOrAssignedValue == false)))
        {
            this.SendPropertyChanging();
            if ((previousValue != null))
            {
                this._Customer.Entity = null;
                previousValue.Orders.Remove(this);
            }
            this._Customer.Entity = value;
            if ((value != null))
            {
                value.Orders.Add(this);
                this._CustomerID = value.CustomerID;
            }
            else
            {
                this._CustomerID = default(string);
            }
            this.SendPropertyChanged("Customer");
        }
    }
}
Private _Customer As EntityRef(Of Customer)
<Association(Name:="FK_Orders_Customers", Storage:="_Customer", ThisKey:="CustomerID", IsForeignKey:=True)> _
Public Property Customer() As Customer
    Get
        Return Me._Customer.Entity
    End Get
    Set(ByVal value As Customer)
        Dim previousValue As Customer = Me._Customer.Entity
        If (((previousValue Is value) _
           = False) _
           OrElse (Me._Customer.HasLoadedOrAssignedValue = False)) Then
            Me.SendPropertyChanging()
            If ((previousValue Is Nothing) _
               = False) Then
                Me._Customer.Entity = Nothing
                previousValue.Orders.Remove(Me)
            End If
            Me._Customer.Entity = value
            If ((value Is Nothing) _
               = False) Then
                value.Orders.Add(Me)
                Me._CustomerID = value.CustomerID
            Else
                Me._CustomerID = CType(Nothing, String)
            End If
            Me.SendPropertyChanged("Customer")
        End If
    End Set
End Property

備註

使用這個屬性來表示資料庫中的關聯,例如外鍵與主鍵之間的關聯性。

在下列範例中,類別 Order 包含將 AssociationAttribute Orders 與 Customers 建立關聯的屬性。

建構函式

AssociationAttribute()

初始化 AssociationAttribute 類別的新執行個體。

屬性

DeleteOnNull

處於其外部索引鍵成員都不可為 null 的 1:1 關聯時,若關聯設為 null 則會刪除物件。

DeleteRule

取得或設定關聯的刪除行為。

IsForeignKey

取得或設定成員,做為表示資料庫關聯性之關聯中的外部索引鍵。

IsUnique

取得或設定外部索引鍵的唯一性條件約束表示。

Name

取得或設定資料行的名稱。

(繼承來源 DataAttribute)
OtherKey

取得或設定目標實體類別的一個或多個成員,做為關聯另一端的索引鍵值。

Storage

取得或設定私用儲存欄位,以存放來自資料行的值。

(繼承來源 DataAttribute)
ThisKey

取得或設定實體類別的成員,表示關聯這一端的索引鍵值。

TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。

(繼承來源 Attribute)

方法

Equals(Object)

傳回值,這個值指出此執行個體是否與指定的物件相等。

(繼承來源 Attribute)
GetHashCode()

傳回這個執行個體的雜湊碼。

(繼承來源 Attribute)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。

(繼承來源 Attribute)

適用於