AssociationAttribute Class
Designates a property to represent a database association, such as a foreign key relationship.
Assembly: System.Data.Linq (in System.Data.Linq.dll)
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 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");
}
}
}
System.Attribute
System.Data.Linq.Mapping.DataAttribute
System.Data.Linq.Mapping.AssociationAttribute
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.