This documentation is archived and is not being maintained.

AssociationAttribute Class

Designates a property to represent a database association, such as a foreign key relationship.

Namespace:  System.Data.Linq.Mapping
Assembly:  System.Data.Linq (in System.Data.Linq.dll)

'Declaration
<AttributeUsageAttribute(AttributeTargets.Property Or AttributeTargets.Field, AllowMultiple := False)> _
Public NotInheritable Class AssociationAttribute _
	Inherits DataAttribute
'Usage
Dim instance As AssociationAttribute

Use this attribute to represent an association in a database, such as the relationship between a foreign key and a primary key.

In the following example, the Order class includes an AssociationAttribute attribute to associate Orders with Customers.

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

System.Object
  System.Attribute
    System.Data.Linq.Mapping.DataAttribute
      System.Data.Linq.Mapping.AssociationAttribute

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5
Show: