AssociationAttribute Classe
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Definisce una proprietà per rappresentare un'associazione di 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à
- 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 )))
{
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
| Nome | Descrizione |
|---|---|
| AssociationAttribute() |
Inizializza una nuova istanza della classe AssociationAttribute. |
Proprietà
| Nome | Descrizione |
|---|---|
| DeleteOnNull |
Se posizionato su un'associazione 1:1 i cui membri di chiave esterna sono tutti non nullable, elimina l'oggetto quando l'associazione è 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 chiave sull'altro lato dell'associazione. |
| Storage |
Ottiene o imposta un campo di archiviazione privato per contenere il valore da una colonna. (Ereditato da DataAttribute) |
| ThisKey |
Ottiene o imposta i membri di questa classe di entità per rappresentare i valori di chiave su questo lato dell'associazione. |
| TypeId |
Se implementato in una classe derivata, ottiene un identificatore univoco per questo Attribute. (Ereditato da Attribute) |
Metodi
| Nome | Descrizione |
|---|---|
| Equals(Object) |
Restituisce un valore che indica se questa istanza è uguale a un oggetto specificato. (Ereditato da Attribute) |
| GetHashCode() |
Restituisce il codice hash per questa istanza. (Ereditato da Attribute) |
| GetType() |
Ottiene il Type dell'istanza corrente. (Ereditato da Object) |
| IsDefaultAttribute() |
Quando sottoposto a 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 è uguale a un oggetto specificato. (Ereditato da Attribute) |
| MemberwiseClone() |
Crea una copia superficiale del Objectcorrente. (Ereditato da Object) |
| ToString() |
Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object) |
Implementazioni dell'interfaccia esplicita
| Nome | Descrizione |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Esegue il mapping di un set di nomi a un set corrispondente di identificatori dispatch. (Ereditato da Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Recupera le informazioni sul tipo per un oggetto, che può essere utilizzato per ottenere le informazioni sul tipo per un'interfaccia. (Ereditato da Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
Recupera il numero di 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 alle proprietà e ai metodi esposti da un oggetto . (Ereditato da Attribute) |