AssociationAttribute Classe

Definizione

Definisce una proprietà per rappresentare un'associazione del database, ad esempio una relazione di chiave esterna.

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
Ereditarietà
AssociationAttribute
Attributi

Esempio

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

Commenti

Utilizzare questo attributo per rappresentare un'associazione in un database, ad esempio la relazione tra una chiave esterna e una chiave primaria.

Nell'esempio seguente la Order classe include un AssociationAttribute attributo per associare Orders a Customers.

Costruttori

AssociationAttribute()

Inizializza una nuova istanza della classe AssociationAttribute.

Proprietà

DeleteOnNull

Quando viene inserita in un'associazione 1:1 i cui membri della chiave esterna sono tutti non nullable, consente di eliminare l'oggetto quando l'associazione viene impostata su null.

DeleteRule

Ottiene o imposta il comportamento di eliminazione per un'associazione.

IsForeignKey

Ottiene o imposta il membro come chiave esterna in un'associazione che rappresenta una relazione di database.

IsUnique

Ottiene o imposta l'indicazione di un vincolo di univocità sulla chiave esterna.

Name

Ottiene o imposta il nome di una colonna.

(Ereditato da DataAttribute)
OtherKey

Ottiene o imposta uno o più membri della classe di entità di destinazione come valori delle chiavi sull'altro lato dell'associazione.

Storage

Ottiene o imposta un campo di archiviazione privato per contenere il valore di una colonna.

(Ereditato da DataAttribute)
ThisKey

Ottiene o imposta i membri di questa classe di entità per rappresentare i valori delle chiavi su questo lato dell'associazione.

TypeId

Quando è implementata in una classe derivata, ottiene un identificatore univoco della classe Attribute.

(Ereditato da Attribute)

Metodi

Equals(Object)

Restituisce un valore che indica se questa istanza è uguale a un oggetto specificato.

(Ereditato da Attribute)
GetHashCode()

Restituisce il codice hash per l'istanza.

(Ereditato da Attribute)
GetType()

Ottiene l'oggetto Type dell'istanza corrente.

(Ereditato da Object)
IsDefaultAttribute()

In caso di override in una classe derivata, indica se il valore di questa istanza è il valore predefinito per la classe derivata.

(Ereditato da Attribute)
Match(Object)

Quando è sottoposto a override in una classe derivata, restituisce un valore che indica se questa istanza equivale a un oggetto specificato.

(Ereditato da Attribute)
MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Implementazioni dell'interfaccia esplicita

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

Esegue il mapping di un set di nomi a un set corrispondente di ID dispatch.

(Ereditato da Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera le informazioni sul tipo relative a un oggetto, che possono essere usate per ottenere informazioni sul tipo relative a un'interfaccia.

(Ereditato da Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Recupera il numero delle interfacce di informazioni sul tipo fornite da un oggetto (0 o 1).

(Ereditato da Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Fornisce l'accesso a proprietà e metodi esposti da un oggetto.

(Ereditato da Attribute)

Si applica a